Marcel Müller <
news.5...@spamgourmet.org> wrote in news:50e163e5$0
$6581$
9b4e...@newsspool3.arcor-online.net:
> I have a folder structure like
>
> - src
> - core
> - core.cpp
> - core.h
> - gui
> - gui.cpp
> - gui.h
> - Makefile
>
> The question is how to write #include directives correctly.
>
> In core.cpp:
> #include "core.h"
> or
> #include "core/core.h"
>
> In gui.h:
> #include "../core/core.h"
> or
> #include "core/core.h"
>
> The compiler is always invoked from src. So the current directory from
> this point of view is src. But the current directory from the files is
> src/core or src/gui respectively. #include claims to search in the
> current directory first. But /which/ current directory?
This is all implementation-defined, so you would need to consult your
compiler documentation. However, many compilers (including gcc) search
the directory of the .cpp first. If it looks like the current working
directory of the compiler process also works, then this is most probably
only because a Makefile or equivalent has added a -I. option somewhere.
But as said, this is all implementation-defined, MSVC for example also
searches in a number of "previously found" include file directories,
hoping for a good luck in a true MS fashion.
> gcc seem to eat both. But I am unsure whether this is correct.
> None of these directories is in the include search path.
I would vote for:
in core.cpp:
#include "core.h"
In gui.h it depends if the gui subdir is considered a separate project or
not. In a separate project:
#include <core/core.h>
(and add src on the include path when compiling the gui project).
In one big project
#include "../core/core.h"
would also be fine (the code would be very tightly coupled anyway).
This is a matter of taste though, I know people who frown upon any
occurence of ".." in the include lines.
Cheers
Paavo