Linking dependencies into static library / Partial linking
Philip K.F. Hölzenspies
p.k.f.holzenspies@utwente.nl
Mon Jan 14 16:41:00 GMT 2008
Dear David, All,
On Friday 11 January 2008 18:12:41 Dave Korn wrote:
> It's looking for the mangled versions; the library, as you point out, has
> only unmangled versions. If you change the start of bar.c from:
When I compile with "g++ -c bar.c" it does, indeed, give an object file with
mangled names. This was a considerable oversight on my part. Thank you for
pointing this out.
> extern "C" {
> #include "foo.h"
> }
I just realized, actually, that in this case there should be
#ifdef __cplusplu
extern "C" {
#endif
in foo.h.
> it will link ok. (Don't forget to manually pass 'this' as the first arg
> when calling C++ non-static class member functions from C, of course.)
Absolutely right, there. It was a bit of a sloppy omission when drawing up
this minimal example. Your help has brought me to the point where I can
actually get on with my work.
I also found an answer to the other part of my question (wanting to use
a "plain C" compiler/linker to compile my C program, while still using this
C++ library). Johan Petersson makes some very useful comments on the matter
here:
http://www.trilithium.com/johan/2005/06/static-libstdc/
Regards,
Philip
More information about the Binutils
mailing list