5
votes

I know that there is a flag that can be used in makefile to include a header file in all the files which are being compiled, just like there is a -D flag to include a define. What flag is exactly for including header files. I don't remember know.

2
Makefiles don't use header files. What are you trying to do? - Ignacio Vazquez-Abrams
I'm guessing that you're trying to force a specific .h file to be included via makefile magic? But then people reading your code and not your makefile will then be mystified as to where important portions of the code reside. IMNSHO, it's better to actually #include the file, but use make to specify the "-I./foo/" flags during the build. Much more maintainable. - tbert

2 Answers

8
votes

In your compile command, you can use the -include option:

gcc -o main -include hello.h main.cpp 
0
votes

something like this maybe? include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)