I have a directory maths which is a library that is comprised solely of header files.
I am trying to compile my program by running the following command in my home directory:
g++ -I ../maths prog1.cpp prog2.cpp test.cpp -o et -lboost_date_time -lgsl -lgslcblas
but I get the following compilation error:
prog1.cpp:4:23: fatal error: maths/Dense: No such file or directory
compilation terminated.
prog2.cpp:6:23: fatal error: maths/Dense: No such file or directory
compilation terminated.
maths is located in the same directory(i.e. my home directory) as the .cpp files and I am running the compilation line from my home as well.
prog1.cpp and prog2.cpp have the following headers
#include<maths/Dense> on lines 4 and 6 respectively, hence I am getting the error.
how do I fix it.
Your include path is given as
-I ../maths. You need-I ./maths– or simpler,-I mathssincemathsis a subdirectory of the current directory, not of the parent directory. Right?Then in your C++ file, use
#include <Dense>. If you want to use#include <maths/Dense>you need to adapt the include path. However, using-I.may lead to massive problems1, I strongly advise against this.Instead, it’s common practice to have an
includesubdirectory that is included. So your folder structure should preferably look as follows:Then use
-I include, and in your C++ file,#include <maths/Dense>.1) Consider what happens if you’ve got a file
./map.cppfrom which you generate an executable called./map. As soon as you use#include <map>anywhere in your code, this will try to include./mapinstead of themapstandard header.