This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: C library in C++
- From: lrtaylor at micron dot com
- To: <tatai123 at rediffmail dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Mon, 18 Aug 2003 10:37:38 -0600
- Subject: RE: C library in C++
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@adobe.com]
Sent: Friday, August 15, 2003 8:46 AM
To: Debamitro Chakraborti; gcc-help@gcc.gnu.org
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