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 :

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.

I have had a similar issue. I have a mixed code C and C++, and apparently my original project was created as a C Project (I didn’t have the GNU C++ in Paths and Symbols and Languages). And although I added the appropriate paths, still I got plenty of errors that the type can’t be resolved in my C++ code that used the C routines. However, when I created a new C++ project, and added the paths to GNU C++ in Paths and Symbols, refreshed the index, automagically I the errors that the type can’t be resolved disappeared.