UBUNTU C ++ compiler does not find header files

I am trying to compile a basic C ++ program with three files: main.cpp, file.h and file.cpp.

When I put   c++ -pthread *.cpp

it it gives me an error message;

fatal error: file.h: No such file or directory
compilation terminated.

      

main.cpp and file.cpp have #include "file.h"

+3


source to share


1 answer


g++ -I. *.cpp

      

This tells the compiler that it finds the header files in the current directory, not just the default directories (/ usr / include and / include).

I suggest you use GNU Make to compile this trivial example. Standard rules will work for you.



make file.cpp main.cpp

      

Perhaps if you have the same problem (.h file not found) you can set CXXFLAGS = -I.

+1


source







All Articles