RE: C library in C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It looks like you're probably also doing this, but you want to make sure that the static libraries you're linking to come after all of your program's object files - basically, the libraries should be pretty much last on the command line.  Otherwise, when the linker finishes processing the static library, it throws away any symbols that weren't needed up to that point and any following modules that do need those symbols will never know that they were ever there, giving you undefined symbol errors, even though the symbols were in fact in the library.

Thanks,
Lyle Taylor
IS Applications

-----Original Message-----
From: Eljay Love-Jensen [mailto:eljay@xxxxxxxxx]
Sent: Friday, August 15, 2003 8:46 AM
To: Debamitro Chakraborti; gcc-help@xxxxxxxxxxx
Subject: Re: C library in C++

Hi Debamitro,

Usually with a problem like this, it's because the C header files were not created with C++ in mind, and don't have the C linkage specified for C++.

This will cause C++ name mangling on their C identifiers, which won't match up to the identifiers present in their archive library.

To get around that, do this with those (naughty?) C header files in your C++ program:

Old...
#include "Qt/xxx.h"

New...
extern "C" {
#include "Qt/xxx.h"
}

Another solution that's a little bit less cluttered in your own source code is to make your own C++ version of their non-C++-savvy C header files.

--------8<--------
// Qt/xxx.hpp
extern "C" {
#include "Qt/xxx.h"
}
--------8<--------

Then you #include "Qt/xxx.hpp", which is merely your C++-savvy wrapper header file.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux