f



compiling c code but libraries are compiled in c++

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

0
sumit
5/29/2007 11:11:14 AM
comp.os.linux.embedded 3347 articles. 0 followers. tvnaidu2 (4) is leader. Post Follow

2 Replies
1358 Views

Similar Articles

[PageSpeed] 16

On 29 May 2007 04:11:14 -0700 sumit <sumit.shrivastava09@gmail.com> wrote:

|   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 |
|------------------------------------/-------------------------------------|
0
phil
5/29/2007 11:55:41 AM
On May 29, 1:11 pm, sumit <sumit.shrivastav...@gmail.com> wrote:

>    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.

the problem is the name mangling of the C++ compiler:
http://www.new-brunswick.net/workshop/c++/faq/mixing-c-and-cpp.html

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

extern "C" {
#include <cunit.h>
}

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 | http://debian.org

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

0
Matthias
5/29/2007 12:52:17 PM
Reply: