How to link libraries with Code::Blocks?
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.
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.
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.
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.
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.
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.
Also double/tripple/.. check, that you got the Search Directories right. It's rather easy to misplace a path into the compiler tab.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement