c++command-linecompiler-errorsg++

How to command-line compile with files in a parent directory?


I'm attempting to compile a C++ program from the Terminal in Mac OS X 10.7.5, but I'm running into some errors. I have a folder which stores my debugging tests, and I'm storing the files I have to #include.

The files are as follows: testCard.cpp, card.cpp, and card.h.

When I try and compile as follows, attempting to use the -I flag to put the parent directory as the first file in the search path:

g++ -g -Wall testCard.cpp card.cpp -I..

I receive the error:

card.cpp: No such file or directory

Even though card.cpp is included in the parent directory. I have also tried the -L and -isystem flags, and neither work. How does one add the parent directory to the search path for command-line compilation?


Solution

  • Even though card.cpp is included in the parent directory.

    -I affects the search path for includes; it does not affect where the source file inputs are looked up, at all.

    So:

    g++ -g -Wall testCard.cpp ../card.cpp -I..