To set up your compiler to find header files in different directories, you need to specify the include paths using compiler flags. The exact flag depends on your compiler.
I
flag followed by the directory path./I
flag followed by the directory path.For example, if you have headers in a directory named "include" within your project directory, you would compile your code like this:
GCC/Clang:
eg++ -I./include main.cpp
MSVC:
cl /I.\include main.cpp
You can specify multiple include paths by using multiple -I
or /I
flags.
In your code, you can then use the #include
directive with the header file name, without specifying the full path:
#include "myheader.h"
The compiler will search for myheader.h
in the specified include directories.
Many IDEs and build systems (like CMake) provide ways to set include paths in their project settings, so you don't have to specify them manually on each compile.
Answers to questions are automatically generated and may not have been reviewed.
A quick introduction to namespaces in C++, alongside the standard library and how we can access it