Archived Forum Post

Index of archived forum posts

Question:

Compile/Link C Program with C++ Library

Dec 10 '15 at 10:21

I get the following errors when trying to compile my "C" program with the Chilkat library:

/usr/lib/chilkat-9.5.0-x86_64-linux-gcc/lib/libchilkat-9.5.0.a(C_CkCrypt2.o):(.data.DW.ref.gxx_personality_v0[DW.ref.gxx_personality_v0]+0x0): undefined reference to __gxx_personality_v0'
/usr/lib/chilkat-9.5.0-x86_64-linux-gcc/lib/libchilkat-9.5.0.a(CkCrypt2.o): In functionCkCrypt2::createNew()':
CkCrypt2.cpp:(.text+0x710e): undefined reference to operator new(unsigned long)'
CkCrypt2.cpp:(.text+0x712b): undefined reference tooperator delete(void)'
CkCrypt2.cpp:(.text+0x713c): undefined reference to __cxa_begin_catch'
CkCrypt2.cpp:(.text+0x7141): undefined reference to__cxa_end_catch'
/usr/lib/chilkat-9.5.0-x86_64-linux-gcc/lib/libchilkat-9.5.0.a(CkCrypt2.o): In function CkCrypt2::~CkCrypt2()':
CkCrypt2.cpp:(.text+0x70fd): undefined reference tooperator delete(void)'


Answer

Anytime you see link errors such as this:

    /usr/lib/chilkat-9.5.0-x86_64-linux-gcc/lib/libchilkat-9.5.0.a(C_CkCrypt2.o):(.data.DW.ref.gxx_personality_v0[DW.ref.gxx_personality_v0]+0x0): undefined reference to __gxx_personality_v0'
    /usr/lib/chilkat-9.5.0-x86_64-linux-gcc/lib/libchilkat-9.5.0.a(CkCrypt2.o): In functionCkCrypt2::createNew()':
    CkCrypt2.cpp:(.text+0x710e): undefined reference to operator new(unsigned long)'
    CkCrypt2.cpp:(.text+0x712b): undefined reference tooperator delete(void*)'
    CkCrypt2.cpp:(.text+0x713c): undefined reference to __cxa_begin_catch'
    CkCrypt2.cpp:(.text+0x7141): undefined reference tocxa_end_catch'
where you see strings such as:
    gxx_personality
    operator new
    operator delete
    cxa_begin_catch
    cxa_end_catch
These are all indicators that you need to link the C++ runtime libs. To do that, use the g++ command instead of gcc.

Also.. compile and link your program in 2 steps. First compile using gcc w/ the "-c" option to produce a .o. The link with g++ so that the C++ runtime libs get linked in.