This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Can C and C++ object files be linked into an executable?


I think this was the answer I was looking for.
By the way, was this the correct place to post it?
Ray

Ferad Zyulkyarov wrote:
Hi,

If you want to phrase the question in terms of object file format and
linker issues, the answer is that the format is the same.

It's easy to see why: the compiler does not produce object files.  It
produces files containing assembly language.  The assembler produces
object files.  The C and C++ compilers use the same assembler.

Before passing the ball to the assembler the compiler does name mangling. It is different for C and C++ and the actual problem at link time comes from here. If you have C++ sources and can compile these sources and later link with the C object files surround your method declarations with

extern "C" {...}

This may help. If you don't have the c++ sources, create wrappers
either to C object files or C++. For now I don't know any other
alternative.



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