Re: #include files from another directory
From: David Fisher (nospam_at_nospam.nospam.nospam)
Date: 01/15/04
- Next message: dullboy: "linker errors: LNK2005"
- Previous message: Jacques Labuschagne: "Re: #include files from another directory"
- In reply to: Christopher: "#include files from another directory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 15 Jan 2004 16:50:48 +1100
"Christopher" <anon@nospam.net> wrote:
> What is the syntax for including files from another directory? In my case
I
> want to include a file called "error.h" which lies in a directory called
> "support" which is a directory inside the (project/solution/source or
> whatever you may call it) directory.
>
> it looks like this (hope the ascii comes out)
> dir engine_x
> ....dir support
> .............file error.h
> .............file error.cpp
> ....file main.cpp
There are a few options:
1. Your C++ compiler probably has a flag to let you specify where to look
for include files other than the current directory. For gcc the flag is
"-I"; for Visual C++ 6.0, look in Tools -> Options -> Directories.
2. You can #include a file in a relative directory, eg. #include
"engine_x/support/error.h" (assuming the current directory is the one below
engine_x). Note that all known include directories are searched, so you
could so something like adding "engine_x" to the include directory list (as
above) and then say #include "support/error.h"
3. (Never do this !) Use the absolute path name, eg. #include
"/home/users/fred/engine_x/support/error.h" This is very bad, because the
code can never be moved around or given to someone else.
BTW. If possible, it might be a good idea to rename "error.h" - it is a
common name, and it might get confusing if the wrong header is included.
David F
- Next message: dullboy: "linker errors: LNK2005"
- Previous message: Jacques Labuschagne: "Re: #include files from another directory"
- In reply to: Christopher: "#include files from another directory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|