Library include paths with same header name

Mircea Ispas picture Mircea Ispas · Mar 2, 2011 · Viewed 9.5k times · Source

What is the best method to include a file that has same name in another folder from additional include directories?

Example:

lib1/include/foo.h
lib2/include/foo.h

where both lib1/include and lib2/include are added in additional include directories.

Edit:

The libs are from different SDK's and every developer installs them in his own place. Only thing that is sure is that both folders are in IDE's additional include paths

method 1:

#include "../../lib1/include/foo.h

method2:

Add lib1/include before lib2/include in search paths and because they are searched in order with:

#include "foo.h"

lib1/include/foo.h will be included

Answer

Bernd Elkemann picture Bernd Elkemann · Mar 2, 2011
#include "lib1/include/foo.h"
#include "lib2/include/foo.h"

Is fine as long as this is the actual relative path to those headers and the include guards are different. For example, if both foo.h use

#ifndef _foo_h_

then this will give you something you dont want (it will only include one, not both and which one depends on the order of execution).