Hi all

Can anyone tell me how I add a linker directory for a specific library to my project in Codeblocks. It would be better if it was there all the time but I think I have to go to Project>Build Options> then I have to select the 'Search Directories' tab, then select the linker tab and compiler tab and enter the directory paths.

I'm pretty sure I have added the header file correctly. I just added the path to the .h file in the parent directory.
But... I'm not sure if I've done the Linker directory right. Is the linker directory the library I built with the .cpp files in it? There's a number of sub-directories with .cpp files, do I inlcude all of these AND,, Can I just add the path?

Thanks very much if you can help me. I'm a bit confused right now.

If you use relative path then your project may not work because some *.cpp files are in different folders so the relative locations will change depending on the location of the *.cpp files. Use full paths and it should be ok.

Edited 4 Years Ago by Ancient Dragon

Hi,, Thank you. But I am using full paths. I'm getting the undefinded reference message x 50 in codeblocks when compiling. Do I add the libraries through the Search Directories option in Codeblocks?

No, search option only tells the linker where to find them. Add library names in Project --> Build Options --> linker settings tab.

Edited 4 Years Ago by Ancient Dragon

Hello again. Well, now I'm confused. If the Search Option tells the linker where to find them, then why isn't that sufficient? ALSO.. What is a Library Name? Does it go like this. I add the library name to the linker setting and then add the actual path to the Search Directory? I really am very new to this and need a little bit of coaching. Please, please. could you be more specific.

I did what I think you said and I get about 10 million of these types of messages.

undefined reference toSelectObject@8'`

Thanks very much for the help above.. Look forward to hearing from you.

Edited 4 Years Ago by christinetom

Library files (.lib) are usually stored in a folder called lib. First you add the path to the search directory, so the compiler knows where the library files are.

But you have to tell the compiler which library file (.lib) to link to.

For example, a lib folder could have the following library files:

lib
|---kernel32.lib
|---user32.lib
|---gdi32.lib
|---winspool.lib
|---comdlg32.lib

Now you just add the library name under the linker settings separated by semi-colons ; (depends on the IDE)

               <library_name.lib>;<another_library.lib>;<third_library.lib>; <etc...>
library files: kernel32.lib;user32.lib;winspool.lib

The errors you are getting means the compiler does not know the function definition (or function body) of the function your calling. The function definition is stored in a library (.lib) file.

But you have to tell the compiler which library file (.lib) to link to.

CB uses gcc compiler/linker so libraries are the same as *nix, which are *.a, not *.lib, so you might have a library named libmylib.a. The name of the libraries are compiler-dependent, many MS-Windows compiler such as Microsoft and Borland use *.lib as previously explained by dx9, but CB does not.

Edited 4 Years Ago by Ancient Dragon

Codeblocks takes a path directly to the library file in the linker settings, not a name. Not sure why its different to your example.

Thanks for the help all. I think I'm ok now, almost there. I have found that there is a way to put the lib file name in codeblocks too.

This question has already been answered. Start a new discussion instead.