5

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.

pythonic
  • 20,589
  • 43
  • 136
  • 219
  • Makefiles don't use header files. What are you trying to do? – Ignacio Vazquez-Abrams Jul 05 '12 at 14:58
  • 2
    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 Jul 06 '12 at 05:07

2 Answers2

9

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

gcc -o main -include hello.h main.cpp 
Linuxios
  • 34,849
  • 13
  • 91
  • 116
0

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

Moataz Elmasry
  • 2,509
  • 4
  • 27
  • 37
  • No, I was talking about a command which includes a certain header file to all the files which are being compiled. Just like you have a -D flag to include a define, such as -DGNU_SOURCE is equivalent to putting #define GNU_SOURCE at the top of each file. – pythonic Jul 05 '12 at 15:01