4

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

As you can see, I have included Locker.h at the top of the file, and it is also listed under 'Header Files' on the left.

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!

Rome_Leader
  • 2,518
  • 9
  • 42
  • 73
  • 1
    Are the files in the same directory? – Floris Velleman Jun 02 '13 at 13:06
  • 1
    See if the header is corectly named and your linker recogneze the path with that. If that header is in curent directory use quotes to include that in other case see if you put the relative path from the root directory of your library. – Mihai8 Jun 02 '13 at 14:49
  • From the png, your error in in SelfStorageList.cpp and you are showing us Locker.cpp. Could you show us all the errors. – cup Jun 02 '13 at 15:42
  • 2
    Please do not use images for problems like this. Copy and paste the code you are having problems with and include the error messages you get from the compiler. You can edit your message by clicking the `edit` link under the question tags. – Captain Obvlious Jun 02 '13 at 17:03
  • FlorisVelleman: Yes, they are. Files are correctly named. I'm not sure I totally follow your suggestion, though. Exact error (to be updated in original post): 1>c:\users\wood\desktop\old programs\locker.cpp(2): fatal error C1083: Cannot open include file: 'Locker.h': No such file or directory @cup The errors in my other file are simply because I have declared functions with no implementation yet, since I didn't begin to work on them yet after noticing this error. – Rome_Leader Jun 02 '13 at 17:55
  • @user1929959 it's not the linker that is giving errors, it's the preprocessor. And the screen shot indicates quotes are already being used. – Kate Gregory Jun 03 '13 at 00:46

2 Answers2

8

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.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
7

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.

  • Thanks! This gave me the idea I needed. I just moved all the files to the same folder and it worked. I guess without the path, it had no idea where to look for the file. But since they are now in the same folder, no need to include the full path name. Thanks! – Rome_Leader Jun 03 '13 at 12:46
  • 6 years after you wrote it, it was a great help for me! Thanks – Or251 Feb 28 '19 at 00:21