How to link libraries with Code::Blocks?

Started by
11 comments, last by Storyyeller 14 years, 10 months ago
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.
I trust exceptions about as far as I can throw them.
Advertisement
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.
------------George Gough
I only have one build (Release).
I trust exceptions about as far as I can throw them.
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.
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.
I trust exceptions about as far as I can throw them.
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.
The same thing

ld.exe||cannot find -lcurl_imp|
I trust exceptions about as far as I can throw them.
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
I already did that. Sorry if my first post wasn't clear enough.
I trust exceptions about as far as I can throw them.
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?

This topic is closed to new replies.

Advertisement