3

With the SDL libraries for example, one would have to point to the headers at the beginning of their code, like so:

#include <SDL/SDL.h> 

And, when compiling with GCC for example the library would then have to be included with:

gcc project.cpp -o project -l/path/to/library/SDL

So, when you are developing a program with a specific library to include, where should the header files and the library be located so that GCC can recognize where to pull that information from? Do they have to be stored in the usr directory or can you tell GCC to point to whatever location you want?

This is specific to development on Ubuntu as that is the platform I am developing for but any *nix platform would likely be similar.

1 Answer 1

2

The GCC compiler will look for headers depending on how you declare the header so there is two possibilities

Declaring the header using angled brackets <>

#include <math.h>

In this case the compiler will search in the default system header locations in Ubuntu it is

  • /usr/local/include
  • /usr/target/include
  • /usr/include

So if your needed library has its header file in one of those locations GCC should find it by default.

Declaring the header with " "

#include "myheader.h"

or

#include "myheaders/header.h"

In this case the compiler will look in the same directory as your .c file is, unless you tell gcc to look somewhere else by using the -Idir option

Further information can be found in this article about Compiling, linking, Makefile, header files on gribblelab.org

3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .