Sign in to follow this  
Storyyeller

How to link libraries with Code::Blocks?

Recommended Posts

I managed to get SDL working successfully before, but now I can't seem to link anything. Whenever I try, it just says cannot find -lwhatever.lib I went to Project - Build Options, set the directory where the lib file is under Search Directories - Compiler and Linker, and then added the lib file under Linker Settings - Link Libraries, but it always gives the same error. What am I missing? When I don't link to anything, it has a bunch of compile errors like obj\Release\main.o:main.c:(.text+0x47)||undefined reference to `__imp__curl_mvsnprintf'| obj\Release\main.o:main.c:(.text+0x18b)||undefined reference to `__imp__curl_mvfprintf'| obj\Release\main.o:main.c:(.text+0x19d)||undefined reference to `__imp__curl_mfprintf'| etc. I figured the problem was that I was missing some sort of library, but I'm not sure what to do.

Share this post


Link to post
Share on other sites
Did you make sure to set it for the whole project and not just one of the builds (Debug, Release, or whatever builds you have). I have done that and it won't link if you do that and try to build a version that doesn't have the link parameters.

Share this post


Link to post
Share on other sites
There are two ways to link against a file in C::B.

Suppose you wish to link against "libSDL.so", you can either add the filename "libSDL.so" to the "Link libraries" box in the linker settings, or you can add "-lSDL" as a linker-option in the "Other linker options" box (note that as a linker option, you have to omit the "lib" at the beginning, and the filename extension ".so").

The error message "cannot find -lwhatever.lib" looks like you used the linker option, but put it into the "Link libraries" box.

Share this post


Link to post
Share on other sites
No, the error message just changes it for some reason


If I put libcurl_imp.lib under Link Libraries, the error message is
ld.exe||cannot find -lcurl_imp.lib|

If I put "libcurl_imp.lib" under Link Libraries, the error message is
ld.exe||cannot find -llibcurl_imp.lib|

It's adding the -l by itself.

Share this post


Link to post
Share on other sites
And if you put "-lcurl_imp" (without the quotes) into the "Other linker options" box?

Also double/tripple/.. check, that you got the Search Directories right. It's rather easy to misplace a path into the compiler tab.

Share this post


Link to post
Share on other sites
Have you configured codeblocks to find the libraries?

Find out where on your computer the <whatever>.lib file is installed (typically under a directory called lib), and add that directory in the codeblocks settings as described here as step 4

Share this post


Link to post
Share on other sites
Sorry, I didn't see that.
The only thing I can think of is that you have installed the wrong libraries. According to this page there is different versions of the libraries. You sure you got the MingW version and not the MSVC?

Share this post


Link to post
Share on other sites
I couldn't figure out what to do, so I just tried throwing in everything I could find.

I figured that even if it was the wrong version of the library or whatever, it should still be able to at least link to it. Am I mistaken?

Anyway, do you know how I would go about finding exactly what I need to build it in Code::Blocks anyway? I tried searching, but I couldn't find anything that really explained the process.

Share this post


Link to post
Share on other sites
I just noticed that the MingW version of libcurl is missing from that download.
Some info here that might help.

Also there is a generic version at the bottom of this page that might work.

Or maybe you can use an alternative

Hard to say what the problem is if you have set up everything right and still get the error. All I know is that the MSVC version will not work, and may very well give you a pretty brain dead error message.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this