compiling c code but libraries are compiled in c++

May 29, 2007 2 Replies

hi, We have written cunit code for testing some APIs. defination of those APIs are in c++ and .so library is created of them. when I compile my cunit code it gets compiled successfully but while liking it gives undefined reference to symbol. can anyone help me in this matter.



Regards Sumit Shrivastava



| We have written cunit code for testing some APIs. defination of | those APIs are in c++ and .so library is created of them. when I | compile my cunit code it gets compiled successfully but while liking | it gives undefined reference to symbol. can anyone help me in this | matter.

C++ mangles the symbols so it can enforce function argument type matching at linking time. You will need to find out how they are mangled and use those same names in C. Or change the C++ programs to define the functions as special C type.

|---------------------------------------/----------------------------------| | Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below | | first name lower case at ipal.net / spamtrap-2007-05-29-0654@ipal.net | |------------------------------------/-------------------------------------|

the problem is the name mangling of the C++ compiler:

formatting link

a extern "C" declaration around the include of C headers should resolve the problem:

extern "C" { #include }

regards

Matthias Kaehlcke Linux Application Developer Barcelona

The yellow ships hung in the air just like bricks dont do (The Hitch-Hiker's Guide to the Galaxy)

using free software / Debian GNU/Linux |

formatting link

gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required