visual C++ fatal error c1083: cannot open include file
-
Samstag, 3. März 2012 01:02
Hi,
I am trying to build a solution which has two projects, one of these is a library which must be compiled, and is a dependency of the main project. This library appear to build fine. However, when trying to build the main project I get the error:
fatal error C1083: Cannot open include file: 'lualib.h': No such file or directory
lualib.h is included with the directive #include "lualib.h" in the file that throws the error, and is a header file in the directory of the library. The library the following directory relative to the main projects directory:..\lualib\lualib relative to the main project directory. I have added this directory to the locations to look for header files by going to the main project preferences and adding this directory as a reference directory.
Nothing stops the error, any suggestions as to what I'm doing wrong?
Alle Antworten
-
Samstag, 3. März 2012 01:10
You haven't added the correct directory is the obvious thing.
First of all where did you add this? Was it to the main project's Additional Include Directories? Secondly, confirm that the path that the project is looking for is where you expect it to be looking. Remember that with relative paths it has to start from the directory where the .vcxproj file is located.
This is a signature
Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this. -
Samstag, 3. März 2012 11:01
Hi Crescens2k,
Well, I have added the search directory by right-clicking on the main project the choosing Prefernces, I then clicked on the 'Add Path' button next to the 'Additional Reference Search Paths' and navigated to the correct directory to add it, so I am pretty certain that the directory I have put in here is the directory where the liblua source files are.
I have tried adding this path as both a relative and absoluted path with no effect.
I have tried altering the include directive as follows:
#include "../liblua/liblua/lualib.h"
And as follows
#include "..\liblua\liblua\lualib.h"
Incidentally I can comple and link the same set of files fine using Code::Blocks and mingw, but need to investigate Visual C++
-
Samstag, 3. März 2012 11:58
Well, even though none of what you said holds any relevence to Visual Studio itself, the problem is that the reference paths are for C++/CLI when you use the #using directive. For .h files you need to set the Include paths, this will add paths to what VC looks in when you use the #include directive.
So to do this in Visual Studio, open up Solution Explorer, right click on the main project's name and then select Properties. In the window that appears go to Configuration Properties->C/C++->General and in Additional Include Directories add the path to the header files. This can be relative or absolute. You must do this for all configurations in your project. Please note that it must be Include for the compiler to associate that with the #include directive. So if you are modifying another IDE then look out for Include.
The directions that I gave will work on VC8 and newer (they should also work on VC7 and 7.1) but I don't know VC 6. So if you are using that then again, look out for the Additional Include Directories setting.
This is a signature
Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
Do you want Visual Studio 11 Express to be freely installable on Windows 7 and able to write regular C++ applications? Please vote for this.- Bearbeitet Crescens2k Samstag, 3. März 2012 12:00
- Als Antwort markiert crobar Sonntag, 4. März 2012 23:02
-
Samstag, 3. März 2012 22:05
assuming you typed the file name correctly, have you tryed the full name path without the double dot short cut?
like: #include"c:\\mydir\\lualib.h"
It needs double slashes. I think backward ones for windows and forward ones for unix/linux.
If the double slash fixes it then retry with the double dot path short cut.
I dont have the experience with visual studio compiling preferences.
Good luck.
David
- Bearbeitet 7david7 Samstag, 3. März 2012 22:25
-
Sonntag, 4. März 2012 23:02Just had a chance to try this, and it worked.
Thanks for the help! -
Sonntag, 4. März 2012 23:05
Hi, the suggestion from the other poster worked, but I may also try yours to get a better understanding of what's going on.
Either way, thanks for the help.
-
Montag, 5. März 2012 00:00>Just had a chance to try this, and it worked.
To which suggestion does this refer?
>the suggestion from the other poster worked
Which "other poster"?
>but I may also try yours
Which one would that be?
Please include enough quoted text in your replies
to allow us to know which post you are referring
to when you make such comments. We have no way
to know what you are *thinking* about when you
post such "orphaned" comments. It has to be
obvious in the messages you post.
- Wayne -
Montag, 5. März 2012 01:55
Look up some info on the precompiler and all that is does for understanding on why you need double slashes in path data. This is more of a problem on windows because of the slash use in path names and the nature of the slash in C++. In C++ its also refered to as an escape character, in case you want to look that up also.
Good luck.
David
-
Montag, 5. März 2012 14:09
#include "c:\\mydir\\lualib.h"
This is not correct. Double slashes are not needed in #include paths. Also, in VC++ you can use either forward or backward slashes, though forward slashes are preferred for portability reasons.
It needs double slashes. I think backward ones for windows and forward ones for unix/linux.
David Wilkinson | Visual C++ MVP -
Montag, 5. März 2012 18:59
davewilk,
Could you elaborate on this please. I know for a fact that many precomilers will cause errors on single slashes in a path statement. Are you refering to Visual Studio compiler tools? Also could you point out the proper way the original poster, crobar, was to write the include statement with parenthesis? Your clarification would benefit us all.
Thank you.
David
- Bearbeitet 7david7 Montag, 5. März 2012 18:59
-
Montag, 5. März 2012 22:52
Could you elaborate on this please. I know for a fact that many precomilers will cause errors on single slashes in a path statement. Are you refering to Visual Studio compiler tools? Also could you point out the proper way the original poster, crobar, was to write the include statement with parenthesis? Your clarification would benefit us all.
I'm not sure I understand your question. What parenthesis?
In both
#include <path>
and
#include "path"
a backslash in the path is not treated as an escape character, and so a single backslash should be used (on Windows).
However, for portability reasons it is universally recommended that forward slash be used as the directory separator.
David Wilkinson | Visual C++ MVP -
Dienstag, 6. März 2012 01:55
That was supposed to be quotes, not parenthesis.
So I can use forward slashes in a windows pathname? I did not know that.
The backslash is not consider an escape character in the path? Surely you mean only in precompiler directives, right. Doesn't the precompiler always treat it as an escape character in string literals in general code? Or is this outdated information?
Thanks again for your input.
David
-
Dienstag, 6. März 2012 14:16
So I can use forward slashes in a windows pathname? I did not know that.
I said that in an include statement (i) the backslash is not an escape character, and (ii) you can use forward slash. The path in an include statement is not a string literal in the normal sense.
The backslash is not consider an escape character in the path? Surely you mean only in precompiler directives, right. Doesn't the precompiler always treat it as an escape character in string literals in general code? Or is this outdated information?
David Wilkinson | Visual C++ MVP

