User forums > Using Code::Blocks
Problem with linking library
(1/1)
dr snuggles:
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
Details about the library:
XMLParser named Xerces
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 ===
--- End code ---
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.
TDragon:
--- Quote from: 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*
--- End quote ---
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:
* Try to choose a different xml parser. The Xerces web site mentions MSVC 6.0 as the method of choice for building and using it. 6.0 was a pre-ISO compiler, and as such has some very nasty incompatibilities and unexpected gotchas. Fortunately, newer and better versions of MSVC have been out for a long time. Don't the Xerces people realize this?
* Try to build and use Xerces with a free version of MSVC, such as 2005 Express or the 2003 Toolkit.
* Try to link your GCC-compiled program with MSVC-compiled Xerces. This generally doesn't work with C++ libraries, however; if the interface tries to pass anything more than simple built-in types -- a std::string object, for instance -- you're toast.
* Try to port Xerces to MinGW/GCC, or find a build by someone who has. If you don't really know what you're doing here, steer clear.
dr snuggles:
--- Quote from: TDragon on March 16, 2007, 02:51:29 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.
--- End quote ---
That's a good tip!
--- Quote ---I can't remember whether the mangled functions in your error log are GCC-style or MSVC-style
--- End quote ---
It's GCC style
--- Quote ---If I'm right, and you are using MinGW/GCC, you could:
*four options*
--- End quote ---
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 :)
Navigation
[0] Message Index
Go to full version