简体   繁体   中英

Compiler Can't Find My Header?

Despite hash-including it, my project cannot seem to find its header file. I have included a screenshot because I think it's the most effective way to showcase my problem:

ERROR MESSAGE

1>c:\\users\\wood\\desktop\\old programs\\locker.cpp(2): fatal error C1083: Cannot open include file: 'Locker.h': No such file or directory

如您所见,我已将Locker.h包含在文件的顶部,并且它也列在左侧的“头文件”下。

Any ideas as to what's gone wrong? I've tried: 1) Cleaning the project and rebuilding it. 2) Creating a brand new, identical project.

Thanks!

Ok, so let's say I have a program with source code located in C:\\Users\\Chuck\\desktop\\programming, but it requires a header file from C:\\Users\\Chuck\\desktop\\headers. I can #include the header all I want, but if I don't include the absolute file name, the compiler will refuse to look in the right place.
With you, however, the easiest solution you might try would be to include the absolute path to the header file. So if it's located at

C:\Users\Wood\desktop\old programs\locker.h

you might try including that instead of simply "locker.h"
Code::Blocks gets real fidgety with me if I don't include the header file in the same directory. Normally I can work around that using this same method. Try it, see if it works.

Double click locker.h in the Solution Explorer to open it, then hover over the tab to see the full path. Switch to the file that is trying to include it and hover over the tab to see the full path. If the two files are not in the same folder, you will have to do one of these things:

  • adjust your "C++ Include Directories" property (type "include" in the Quick Launch area at the top right of the screen to find that property
  • use a relative path eg #include "..\\headers\\Locker.h"
  • copy the file to the same folder as the .cpp file, remove it from the project (so the old location isn't important any more), delete that old copy, then use Add Existing to add the newly-copied version (that is in the same folder as the .cpp) to the project again

One of these should do the trick.

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