Jump to content
  • Advertisement
Sign in to follow this  
Storyyeller

How to link libraries with Code::Blocks?

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

If you intended to correct an error in the post then please contact us.

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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!