Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

including .h file from a different application/directory

Tags:

c++

linux

include

I have some .h files as follows (on Linux)

Source/Server/connect.h
Source/Server/message.h
...

I am developing another application that needs the two .h files but is in a different directory

Source/App2/..

How can I include the connect.h file in the App2 application, considering that I use perforce and everyone else working on the application would have their own copy so adding an absolute path to the include library might not be a good idea but im not sure.

EDIT: I use a proprietary build mechanism for building the code so will not be able to specify gcc options directly.

like image 225
randomThought Avatar asked Dec 04 '09 21:12

randomThought


1 Answers

You can #include a relative path to the files:

#include "../Server/connect.h"

or you can add a flag to tell the compiler to look in the other directory. For gcc you can use -I../Server; for Visual C++ you can use /I"../Server"; other compilers, I'm sure, have their own flags for this purpose.

I think the second is better in most cases, since it allows you to move your projects around while only requiring you to modify the include path in one place (the makefiles or property sheets).

like image 81
James McNellis Avatar answered Oct 16 '22 17:10

James McNellis