Sign in to follow this  

linking c and c++ object files

This topic is 4815 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
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

This topic is 4815 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this