Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: KirkD on August 07, 2009, 07:53:40 pm

Title: Setting up 3rd party libraries
Post by: KirkD on August 07, 2009, 07:53:40 pm
I have a 3rd party library (OpenBabel - www.openbable.org) that was built using VC++ Express 2008 that I'm trying to use in Code::Blocks.  I can link to this library and compile an application through VC++ Express 2008 or through Code::Blocks if I specify VC++ as the compiler of choice.  But, when I switch go the GCC compiler and (to the best of my knowledge) have the libraries specified as well as the correct search paths, I always get "undefined reference to" errors referring to functions within the OpenBabel libraries.

Is it not possible to link to a library built with another compiler?  I could rebuild with GCC, but I would prefer to use these prebuilt libraries.

I appreciate any assistance!

-Kirk

Title: Re: Setting up 3rd party libraries
Post by: MortenMacFly on August 07, 2009, 08:10:53 pm
Is it not possible to link to a library built with another compiler?
It is possible. Notice that you just need to resolve the missing references - that's it. From my experience I can say that usually the import of VC projects into C::B works just fine. Just in a VC project you don't need to explicitly define all required libraries. Visual Studio seems to do some "voodoo" so that in the end the linker is happy. C::B doesn't do such (luckily) so you must make sure that you have setup the project correctly.
So far I had only one (!) VC library that I was not able to use with GCC. Every else worked just fine - even such things like Direct/X.
Title: Re: Setting up 3rd party libraries
Post by: KirkD on August 07, 2009, 08:14:34 pm
Morten,

Thanks for the reply.  I suppose it is at least comforting to know that it is possible.

At this point I've added every library in that I have and pointed to all the appropriate search directories, as far as I know.  Any suggestions on where to look for what I'm missing?  Or is this part of the "voodoo" - finding the missing parts??

-Kirk
Title: Re: Setting up 3rd party libraries
Post by: MortenMacFly on August 07, 2009, 08:21:05 pm
Any suggestions on where to look for what I'm missing?  Or is this part of the "voodoo" - finding the missing parts??
Notice that also the order matters. SO if lib1 requires lib2 you cannot link against lib1 in the first place. Here is what I usually do:

- import VC project
- remove all libs from the project's linker options (only the libs)
- compile
- notice the first missing symbol
- ask google what library this is from -> MSDN helps nicely if it's a MS Windows dependency
- if it's "my" stuff I either know or use the symbol table plugin to find the library that exports the missing symbol.
- like this I add all libs needed step by step and automatically have the right order.
Title: Re: Setting up 3rd party libraries
Post by: stahta01 on August 07, 2009, 09:03:34 pm
Is it not possible to link to a library built with another compiler?  I could rebuild with GCC, but I would prefer to use these prebuilt libraries.

If all the exported functions are "C" it is possible. If C++ functions then it is NOT normally possible to change Compilers between client code and library code.

Tim S.
 
Title: Re: Setting up 3rd party libraries
Post by: KirkD on August 07, 2009, 09:28:52 pm
stahta01  -  Interesting.  I'm not sure of the full nature of the library - not my development - so I don't know for certain about the exports. 

I've gone through the VC++ solution file and found all the listed dependencies for the library that seems to be failing.  Even when included in the "proper" order, etc. I cannot get around the reference failure.

So, I have the choice to rebuild using Code::Blocks or start using VC++ Express.  Code::Blocks is certainly my preference, but it may be more efficacious right now to go the other route.

Thank you both for your input!!

-Kirk

Title: Re: Setting up 3rd party libraries
Post by: stahta01 on August 07, 2009, 10:57:51 pm
Compile the Library with the same compiler as the project is the way to go. The Library looks to be C++ to me.

https://sourceforge.net/projects/openbabel/

EDIT: FYI, Code::Blocks is an IDE not an compiler.

Tim S.
Title: Re: Setting up 3rd party libraries
Post by: KirkD on August 07, 2009, 11:30:06 pm
Yes, I realize that Code::Blocks is an IDE - I tend to use Code::Blocks interchangeably with GCC.  oops.  8^)


I'll give the rebuild with GCC a shot.

Title: Re: Setting up 3rd party libraries
Post by: PaulS on August 07, 2009, 11:58:34 pm
If it is C rather than C++ code this link may help -- http://www.emmestech.com/moron_guides/moron1.html (http://www.emmestech.com/moron_guides/moron1.html).  I was able to use a small Microsoft dll by following the advice.  Even if C++ it may give you a clue about some of the problems.

Can't seem to get that link to format correctly -- may need a moron's guide for that too  :D