This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Linking problems, mangling ?


Roland TTK (hamon@timide.stna.dgac.fr.) wrote:
: 
:  Hi
: I have (succesfully ?) compiled my sources under solaris 2.6 with g++ 2.95 but
: I get undefined reference errors when linking. I try to link my object files
: with a library which was compiled by the sun C++ compiler.

You are trying to do something which cannot work.

: It seems like this
: compiler uses a specific mangling grammar, so the linker can't find the
: definitions it needs.

: I think the mangling grammar is pretty old (1994) so I can't beleive gcc
: doesn't emulate it.

You'd better believe it.  Quote from the g++ faq:

------------------------------------------------------------------------

Why can't g++ code link with code from other C++ compilers?

"Why can't I link g++-compiled programs against libraries compiled by
some other C++ compiler?"

Some people think that, if only the FSF and Cygnus Support folks would
stop being stubborn and mangle names the same way that, say, cfront
does, then any g++-compiled program would link successfully against
any cfront-compiled library and vice versa. Name mangling is the least
of the problems. Compilers differ as to how objects are laid out, how
multiple inheritance is implemented, how virtual function calls are
handled, and so on, so if the name mangling were made the same, your
programs would link against libraries provided from other compilers
but then crash when run. For this reason, the ARM encourages compiler
writers to make their name mangling different from that of other
compilers for the same platform. Incompatible libraries are then
detected at link time, rather than at run time.

------------------------------------------------------------------------

This means that you need to compile all C++ source in an application
with one and the same compiler.  With C libraries this problem generally
doesn't exist.

HTH,
Eric

-- 
 E.L. Meijer (tgakem@pebbles.chem.tue.nl)
 Eindhoven Univ. of Technology
 Lab. for Catalysis and Inorg. Chem. (SKA)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]