3

I'm wanting to include files from the parent directory in a project I am working on. All of the header files are in the parent directory, is there any way of using -I on the commandline to search for includes in the parent directory without using an absolute path?

I know I can solve these issues using a makefile and I will probably end up doing this, but I'd like to know if there is a quick commandline trick I can use as this situation pops up a lot when I am making quick prototype code.

Currently I am trying to compile using:

g++ -Wall -I../ simple.cpp

but this seems to not work properly. Will I also need to change the includes in simple.cpp from #include include_file.hpp to #include ../include_file.hpp ?

5
  • 2
    You are doing the right thing. Why do you say it doesn't work properly? Commented Mar 30, 2011 at 7:12
  • You don't need the trailing /, but otherwise this should work OK: g++ -Wall -I.. simple.cpp Commented Mar 30, 2011 at 7:13
  • @trojanfoe, the compiler is not finding the .hpp files and give a No such file or directory error. Commented Mar 30, 2011 at 7:26
  • The path -I.. would be from the directory you start g++ from. Will that always be the right one? Think nested make files? Commented Mar 30, 2011 at 7:41
  • looks as though the -I.. did the trick! Thanks! Commented Mar 30, 2011 at 7:43

1 Answer 1

3

Hmm...

g++ -Wall -I.. simple.cpp

and

// Somewhere in simple.cpp
#include <include_file.hpp>

should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.