Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include headers from different directories in C++

I am about to start writing a code in C++ for my PhD. Until now I worked with small code. All the files (sources and headers) in one directory.

Since I want to write a more organized code, I'll put files in different directories.

So what is the proper way to include files? Should I use something like

#include "../../folder/file.hpp"

It doesn't look very clean. And is the code portable to Windows if includes are done this way?

like image 366
user12436857 Avatar asked Dec 05 '25 17:12

user12436857


1 Answers

is the code portable to Windows

I don't see a reason why it wouldn't be, as long as you fix the syntax of the directive first. I don't have a windows to test at the moment, but that's a valid path.

However, I would recommend to avoid parent directory include paths. Instead, specify a directory as an include directory for the compiler, put all your headers there into sub-directories and include with a path relative to the include directory.

like image 59
eerorika Avatar answered Dec 07 '25 13:12

eerorika