I am trying to learn how to better organize a project and it's files in C++.
My simple test project only seems to work whenever main.cpp (and main.exe) is in the root project folder. Here's how I wanted to try to set it up.
- Project
- .vscode
- c_cpp_properties.json
- headers
- header.h
- main
- main.cpp
- main.exe
- .vscode
Inside of main.cpp, I have #include "headers/header.h"
When I try to compile it with this setup, I get this error
fatal error: headers/header.h: No such file or directory
I am wondering why this doesn't work when the following setup, which doesn't have main.cpp in a subfolder, compiles and runs just fine (without changing any of the code).
- Project
- .vscode
- c_cpp_properties.json
- headers
- header.h
- main.cpp
- main.exe
- .vscode
I am using Visual Studio Code with the C/C++ and C/C++ Compile Run extensions (in case that's relevant).
Edit:
Changing it to "../headers/header.h"
does work, but I am wondering how I would do this without using ../
.
If I'm understanding correctly I just need to add something to the includePath in c_cpp_properties.json. Here's what the "includePath"
section looks like right now.
"includePath": [
"${workspaceFolder}/**"
],
So I think I just need to make it something like
"includePath": [
"${workspaceFolder}/**",
"..."
],
What exactly should I be putting in the ...
part?