Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: dr snuggles on March 16, 2007, 02:23:21 pm

Title: Problem with linking library
Post by: dr snuggles on March 16, 2007, 02:23:21 pm
I'm trying to link a library with Code::Blocks, but I get linker errors :(. What should I do to properly link libraries in C::B ?

What I thought was good, but did not help:
Going to settings -> compiler & debug -> global compiler settings -> linker settings -> add -> *libraries*

What else I tried:
Many things, even changing some advanced compiler settings as mentioned here (http://forums.codeblocks.org/index.php?topic=137.msg553)

Details about the library:
XMLParser named Xerces (http://www.apache.org/dist/xml/xerces-c/)

Details about my setup:
Code::Blocks build SVN 3683 (11 March 2007)
Windows XP

The linker errors I get:
Code
undefined reference to `_imp___ZTVN11xercesc_2_714DefaultHandlerE'
undefined reference to `_imp___ZTVN11xercesc_2_714DefaultHandlerE'
undefined reference to `_imp___ZTVN11xercesc_2_714DefaultHandlerE'
undefined reference to `_imp___ZTVN11xercesc_2_714DefaultHandlerE'
undefined reference to `_imp___ZTVN11xercesc_2_714DefaultHandlerE'
undefined reference to `_imp___ZN11xercesc_2_717SAXParseExceptionC1ERKS0_'
undefined reference to `_imp___ZN11xercesc_2_79XMLString9transcodeEPKt'
...
undefined reference to `_imp___ZNK11xercesc_2_717SAXParseException13getLineNumberEv'
undefined reference to `_imp___ZN11xercesc_2_79XMLString7releaseEPPc'
undefined reference to `_imp___ZN11xercesc_2_716XMLPlatformUtils9TerminateEv'
undefined reference to `_imp___ZN11xercesc_2_77XMemorynwEjPNS_13MemoryManagerE'
undefined reference to `_imp___ZN11xercesc_2_717SAX2XMLReaderImplC1EPNS_13MemoryManagerEPNS_14XMLGrammarPoolE'
undefined reference to `_imp___ZN11xercesc_2_77XMemorydlEPvPNS_13MemoryManagerE'
:: === Build finished: 30 errors, 0 warnings ===

What the linker errors mean (I think):
Function header was found, but not the implementation. Meaning: linking a library is not done right or not working.
Title: Re: Problem with linking library
Post by: TDragon on March 16, 2007, 02:51:29 pm
I'm trying to link a library with Code::Blocks, but I get linker errors :(. What should I do to properly link libraries in C::B ?

What I thought was good, but did not help:
Going to settings -> compiler & debug -> global compiler settings -> linker settings -> add -> *libraries*
Bad idea; this would mean that every program you try to compile under Code::Blocks would be linked with those libraries. The "Linker settings" section of your project's Build options dialog is the correct place to define these.

I note that Xerces under Windows appears to support being built only with Microsoft Visual C++. I can't remember whether the mangled functions in your error log are GCC-style or MSVC-style, and you didn't post which compiler you're using -- I'm guessing that it's MinGW/GCC. If I'm wrong, and you have Visual C++ installed and have a .lib file for Xerces, just add the .lib file to your link libraries in the dialog I mentioned previously.
If I'm right, and you are using MinGW/GCC, you could:
Title: Re: Problem with linking library
Post by: dr snuggles on March 16, 2007, 03:15:27 pm
Bad idea; this would mean that every program you try to compile under Code::Blocks would be linked with those libraries. The "Linker settings" section of your project's Build options dialog is the correct place to define these.
That's a good tip!
Quote
I can't remember whether the mangled functions in your error log are GCC-style or MSVC-style
It's GCC style
Quote
If I'm right, and you are using MinGW/GCC, you could:
*four options*
This sounds like there is no option for me to use CB + Xerces + Windows.

Thanks for your suggestions and help. I'll try CB under Linux to see if that works better. At least it should link properly :)