In my current project I have separated my class files and my header files. My project structure currently looks like this:
Project
My problem is that I do not know how to include the header files into the class files. Am I unable to link to headers that are not at the same level or in a child folder? Or is there some way to go from the project root and work my way down? For instance:#include "Project/Headers/include/class1.h"
inside the class1.cpp file
You can find this option under Project Properties->Configuration Properties->C/C++->General->Additional Include Directories. and having it find it even in lib\headers. You can give the absolute or relative path to the header file in the #include statement.
The way I do it is visual. I put my mouse pointer on the index. php (looking at the file structure), then every time I go UP a folder, I type another "../" Then you have to make sure you go UP the folder structure ABOVE the folders that you want to start going DOWN into. After that, it's just normal folder hierarchy.
Add your include directories there. For Code::Blocks, go to the Project menu and select “Build Options”, then the “Search directories” tab. Add your include directories there. For g++, you can use the -I option to specify an alternate include directory.
The most Pythonic way to import a module from another folder is to place an empty file named __init__.py into that folder and use the relative path with the dot notation. For example, a module in the parent folder would be imported with from .. import module .
Assuming you want class1.cpp to include class1.h you would do something like this
#include "../../Header/class1.h"
The ..
tells the tells the OS to jump 1 directory up when the compiler asks for the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With