Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#include question

Status
Not open for further replies.

Haunter

Programmer
Jan 2, 2001
379
US
Just starting in C++ and need a point of clarity.

#include <somfiel.h> points do a system default directory right?

#include &quot;anotherfile.h&quot; points to a file in same directory as file being compiled, right?

Now how do I point to a file above the current working directory that is not a system default directory?

ty


haunter@battlestrata.com
 
same way you do in the file system

#include &quot;../somefile.h&quot;

-pete
 
also you could
set PATH=$PATH:/home.../yourProjectDirectory
and compile without changes

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I'm not sure that the
Code:
PATH
environmental variable will work with all compilers (e.g. SUN FORTE).

Most compliers provide a compiler command line switch that lets you add directories to the 'include search list'.

Usually (YMMV) this is of the form:
Code:
-I<directory name>
lets you specify additional directories for the #include directive

So, in your problem example:

Code:
CC -g -o testProg -I../ -c testProg.cpp

multiple
Code:
-I
's can be included, e.g.:

Code:
CC -g -o testProg -I../ -I/opt/ORCL -I/opt/tibco -c testProg.cpp

Many people prefer the approach of specifying the directories at the compiler command level (in a makefile?), rather than in the code itself, since it reduces the filesystem dependencies within the code files themselves.
 
Also, keeping those kinds of dependencies out of source files allows you to specify that kind of stuff all in one centralized place, commonly a Makefile. If you ever change directory structure, you don't change all your source files, you just make one change to the Makefile.

That said, the &quot;../&quot; is appropriate sometimes, especially in small, toy projects (until they become useful and big).
 
Thank you all..

I am from a PERL background and we have to include stuff in the program. Makefiles dont exist. I am just getting over a few learning curve issues and you gents are a great help..


haunter@battlestrata.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top