0

I can only use header files that I add to C:\SDL2-w64\include, but I Can't get it to link to the include folder inside my project folder.

for example: I have a folder called "MyProject" and its located at C:\Users\User\Desktop\MyProject, inside the project folder there is an "Include" folder located at \MyProject\Include then I add a header file called "head.h" to the Include path. in my code I use #include <head.h>, I then get the error cannot open source file "head.h", but if I add head.h to C:\SDL2-w64\include it works perfectly fine.

anyone know how to include the Include folder located in my project folder?

  • > anyone know how to include the Include folder located in my project folder? That depends on the compiler you use. – The Dreams Wind May 12 '22 at 06:41
  • 1
    First I suggest you take some time to read [What is the difference between #include and #include "filename"?](https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename) Then please [edit] your question to tell us about your compiler settings. What directories do you tell the compiler to search for header files? – Some programmer dude May 12 '22 at 06:42
  • The file you show seems to be the `c_cpp_properties.json` file, which is only for "compiler path and IntelliSense settings". You need to edit your `tasks.json` file to add directories that should be passed to the compiler itself when building. See e.g. [this GCC and MinGW on Windows with VSCode tutorial](https://code.visualstudio.com/docs/cpp/config-mingw) for details. – Some programmer dude May 12 '22 at 07:05

1 Answers1

2

Assuming the file doing the including is located at C:\Users\User\Desktop\MyProject, try using #include "Include/head.h". This is because there is a difference between using quotations ("") and angle brackets (<>) in your includes.

The reason is explained in this answer: https://stackoverflow.com/a/3162067/19099501

But to summarize it, with most compilers, #include "blah.h" will search in the local directory first, and then the stuff it can reach from what's in your PATH variable, and #include <blah.h> will search from what's in PATH only. I am guessing that C:\SDL2-w64\include is in your PATH. That is probably why when you moved the header file to that location, it was able to find it.

Hachiko
  • 46
  • 2