Include file paths (-I ...)

Derek Atkins warlord at MIT.EDU
Fri Sep 27 10:19:30 EDT 2013


Hi,

Geert Janssens <janssens-geert at telenet.be> writes:

[snip]
> I looked a bit closer and found that we are specifying the include
> search paths as absolut paths
> from the $(top_srcdir), like
> -I$(top_srcdir)/src/gnome-utils, ...

Right...

> Obviously with such a path spec my built source files in the build
> directory never get found.
>
> If I change the above to
> -I../gnome-utils
> (this example is for in the gnome/Makefile.am), it works. That is
> because the compiler will
> expand this path in both the source dir as the build dir.

This is not guaranteed to work in all systems/compilers/environments.
IIRC the issue is that out-of-source builds don't necessarily include
both the source and build trees in their include paths.

> So my question: is that the right approach and secondly, why was the
> $(top_srcdir) notation
> chosen in the first place ?

See above.

We could have done it by -I${top_srcdir} -I${top_builddir} and then used
e.g. #include <engine/Split.h>, etc.   But we don't.

> Note that there were already built sources in the gnucash code. These
> are included using a
> path relative to src, for example
> #include "core-utils/gnc-version.h"
> and the relevant Makefile.am has a pathspec like
> -I$(top_builddir)/src
>
> Seems ... inconsistent ? Or what am I missing ?

I don't think it's inconsistent.  We *know* which include files get
built vs which ones are part of the sources.  So yes, we do treat them
differently.  As I said, the alternative is doing what I suggested
above, using the full path to each header explicitly.  The downside of
this alternate approach is that if you move a header (e.g., business ->
engine) then you need to change every usage of that header.  Moreover,
it fails when you install the headers, unless you keep the same
hierarchy in the install-dir.

> Geert

-derek

-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available


More information about the gnucash-devel mailing list