Add a custom library to a target.
Sébastien Granjoux
seb.sfo@free.fr
Philip Chimento
philip.chimento@gmail.com

# Add a Custom Library

It is easier to use a packaged library, which is common on Linux, so check if it is the case here. But else you can still use the library as explained below.

In order to use a library in C, you need to tell the compiler where the header files are, and tell the linker where to find the needed libraries. The issue is that your program will not compile on another computer if the header and the libraries are elsewhere.

Select the directory containing the program where you want to add the library in the project view, click on the right mouse button to make the project context menu appear and select Properties.

Or from the main menu, select Project Properties. By default, it edits the properties of the currently selected item in the project view. You can select a different item in the drop-down list button.

If the header files are installed in a standard location (/usr/include) you don't have to set this. If not, you need to add -Iinclude_path in the C preprocessor flags property if you are using gcc as your compiler. You can add several paths separated with spaces. These options will be used for all targets inside this directory.

You might have to expand the More options button to see this. Click on the Apply button when you are done.

Next, you need to add the library to a target. Select the target where you want to add the library in the project view, click on the right mouse button to make the project context menu appear and select Properties.

Or from the main menu, select Project Properties. By default, it edits the properties of the currently selected item in the project view. You can select a different item in the drop-down list button.

You need to set the Linker flags property, adding -llibrary_name if your compiler is gcc. library_name is the name of the library file without the lib prefix and without the .a or .so extension.

If the library is in not in a standard directory, gcc can look in additional directories with the option -Llibrary_path.