• 15
• 15
• 11
• 9
• 10

# How to link libraries with Code::Blocks?

This topic is 3208 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 on other sites
I only have one build (Release).

##### 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 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 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 on other sites
The same thing

ld.exe||cannot find -lcurl_imp|

##### 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 on other sites
I already did that. Sorry if my first post wasn't clear enough.