Setting C++ include path via program code line

Per my understanding you did:

#include <absolute/path/to/header/header.h


#include <relative/path/to/header/header.h

But into the header.h some other include are included.

#include <header_1.h>
#include <header_2.h>
#include <header_n.h>

Those other headers haven’t relative/absolute path, so compiler doesn’t know how to find them.

To solve this you can use (using gcc) the -I compiler option:

-I dir

Add the directory dir to the list of directories to be searched for header files during preprocessing. […]

Emphasis mine

So you can use

#include <header.h>

In your file and compile it using

gcc ... -I/path/to/headers ...

Leave a Comment