YopAndMail
YopAndMail

Reputation: 63

Autotools/Automake : the good way to add include path

I have a C++ project using autotools for compiling under a Linux environment. All includes path i wrote in were relative (ex : -I../path0/inc -I../path1/path2/inc -I../../../path3/inc).

Everything was fine until i decide to build my project in tree-build directory because all object files were among the source ones.

Of course, compilation does not work anymore as i expected.

So, there are my questions :

  1. Do i have to add myself @srcdir@ in front of each include ? (ex: AM_CPPFLAGS = -I@srcdir@/path0/inc -I@srcdir@/../path1/inc)
  2. Or what is the good way to do this ?

Upvotes: 1

Views: 1201

Answers (1)

John Bollinger
John Bollinger

Reputation: 180151

  1. Do i have to add myself @srcdir@ in front of each include ? (ex: AM_CPPFLAGS = -I@srcdir@/path0/inc -I@srcdir@/../path1/inc)
  2. Or what is the good way to do this ?

To properly support out-of-tree building, yes, you need to explicitly express include directories relative to the source directory. Also any other source-tree paths in command-line arguments, except only those expressed via make automatic variables representing prerequisites of the rule.

Personally, however, I prefer to use the $srcdir and / or $top_srcdir variable provided by Automake instead of the @srcdir@ substitution from Autoconf.

Upvotes: 1

Related Questions