The question is asked because in some situation the include order really matters. For example, as said on LearnOpenGL or the GLFW doc, glad.h
must be included before glfw3.h
.
For including headers, I have been following the rule that each file should only include its necessary headers explicitly, and headers should all have include guards.
Thus the problem comes. In a project, some files only need glfw3.h
and some only need glad.h
. Then when compiling, how to guarantee the compiler always reads glad.h
before glfw3.h
?
Two solutions I can think of are:
- manually arrange the order of source files when feeding them to the compiler.
- write a new header file called
glad_glfw.h
which contains the two headers in the right order. Then any other files which need to include any of the two include theglad_glfw.h
.
I think 1. would eventually be difficult when the project grows large, and 2. kind of violates the rule of minimum include. So I want to ask if there are any better ways to do this?