Archived Forum Post

Index of archived forum posts

Question:

Including Chilkat "C" Headers in C++ Source Code

Apr 15 '13 at 09:38

I can not compile on linux or windows with NetBeans C++ or CodeBlock C++.......

main.cpp:7: undefined reference to CkSocket_Create()'
main.cpp:9: undefined reference toCkSocket_Dispose(void*)'

g++ -m32 -o main.o -L/chilkat-9.4.0-mingw -lchilkat-9.4.0 -Wl,--enable-auto-import

Tested with NetBeans and Code::Blocks..... Help......


Answer

(I'm not sure why one would choose to use the Chilkat "C" API within a C++ program because it would be more natural to use the Chilkat C++ classes instead.)

To include the Chilkat "C" API headers within a C++ source file, make sure to wrap it in extern "C", such as the following:

extern "C" {

// Include Chilkat "C" headers here...

}
If your application source is compiled as a C++ source, then the names are mangled according to the C++ compiler's name decoration rules. See http://en.wikipedia.org/wiki/Name_mangling A "C" compiler does not mangle names. Therefore, if you compile "C" declarations as a C++ source, you'll get undefined references and/or unresolved externals.