简体   繁体   中英

Having trouble including header files

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM