Adding include paths to your C/C++ project

by rgrunber

Looking at my previous post, you may have probably noticed an error marker on the gimp project itself, along with some scattered through the various files/folders.

The project built and ran just fine, but as you can see, some headers, and types could not be resolved by the CDT. The horror.

There’s some perfectly good documentation explaining how to fix this, but it’s not too hard to just go through a quick example.

We right click on our project, and select properties from the bottom. Expand the “C/C++ General” entry, and select “Paths and Symbols”.

This project uses many other libraries, but let’s just add glib for now. Looking in the configure.ac we can see the project is using glib2. Now since I don’t know exactly where the glib-2.0 includes are on the system I’ll drop down to the command-line (temporarily!) and execute the following :

$ pkg-config --cflags glib-2.0
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include

pkg-config is pretty useful.

Now since I know glib is a C library, I’ll just add /usr/include/glib-2.0 and /usr/lib/glib-2.0/include to the list of C includes.

We’ll apply the changes, and click ok.


Now we can see that our glib includes have resolved, and we can browse references in much the same way we’d do in the JDT. If we’d like to browse other libraries as well we can add them to the list of includes at any time.

To recap, we simply added some paths to our project-specific list of includes, in order to be able to browse and reference their content in the project. If we don’t know the exact location of the libraries on the system, there are convenient tools to help.

About these ads