Re: compiling c code but libraries are compiled in c++



On May 29, 1:11 pm, sumit <sumit.shrivastav...@xxxxxxxxx> 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

.



Relevant Pages

  • Re: Problem Linking (win32)
    ... version of nasm and the latest version of golink. ... extern MessageBoxA ... your application to compile, link and run. ... A consistent error occurs upon the loading of my asm. ...
    (comp.lang.asm.x86)
  • Re: MIDL file query
    ... MIDL just generates the code to declare an MIDL_TYPE_FORMAT_STRING object with external visible, then use the "static" define it. ... The "extern" declares the static storage class object, so there is no problem using the "static" to define it. ... No problem except that for historical reasons I need to compile the file using a non-MS compiler, ... At this stage, I can compile and run the output from MIDL V2, but although I can get the output from MIDL V6 to compile by changing static to extern, as yet have been unable to get it to run without crashing - I think in the RpcServerListen routine the first time a call is made from the client. ...
    (microsoft.public.vc.language)
  • Re: Static _Bool initialization
    ... Are you assuming some kind of wrap-around pointer value, ... Michal Necasek wrote: ... at compile time for the program to compile. ... For all non-array extern objects, ...
    (comp.std.c)
  • Re: gcc compiling problems :extern "C"
    ... I tried with sample files but I couldn't compile the C sourcecode... ... void myfun; ... This code is compiled without the extern "C" declaration in view, ... This now expects an extern "C" myfun() somewhere. ...
    (comp.os.linux.development.apps)
  • Re: [patch] Real-Time Preemption, -RT-2.6.10-rc2-mm2-V0.7.29-0
    ... It doesn't compile. ... I tried to fix the compilation errors with these 2 one-liners: ... extern unsigned long wall_jiffies; ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)