Jump to content
  • Advertisement
Sign in to follow this  
BerwynIrish

linking c and c++ object files

This topic is 4975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it not possible to link a c-source object file (let's call it c-source.o) created with GNU gcc with a c++-source object file (c++-source.o) created with GNU c++? When I try, the linker tells me that all of the references in c++-source.o to the functions in c-source.o are undefined. c-source.o links just fine with c-source2.o, and nm also confirms that the functions c++-source.o refers to are contained in c-source.o

Share this post


Link to post
Share on other sites
Advertisement
It is possible, perhaps you need to do an


In c++ files where you use c header files, you ned to tell the compiler/linker the name will be in c format, like:

extern "C"
{
#include "Whatever.h" //All c source file headers
}

SO the C++ linker/compiler can know the name of the function. Look up c/c++ name mangling

Share this post


Link to post
Share on other sites
Something might have changed between the compiler versions, if you can compile the c file with the c++ compiler then they should link fine.

HTH

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!