开发者

VS2003 can't find .h file even after addition to "additional incl. dirs"

I have file which needs to include blah.h in another project. I've tried adding the director开发者_高级运维y that holds the blah.h file to

Project -> Project Properties -> Additional include directories

but I keep getting a "C1083: Cannot open include file: blah.h: No such file or directory". I've tried absolute and relative paths to the folder housing blah.h with no success.

I'm using Visual Studios 2003. and my include statement looks like

#include "blah.h"

Any suggestions?


Get the build (or at least this part of the build) working using:

#include "c:/path/to/blah.h"

If/when VS stops complaining about not being able to find blah.h, cut-n-paste the path used in the #include into the "Additional include directories". Remember that the "Additional include directories" field should have the directories separated by a semi-colon.

Also, make sure that you set the "Additional include directories" property for all appropriate build configurations and platforms (drop-downs at the top of the Project property page dialog). Since the dialog opens up with only the "Active" configuration selected, I often find myself setting up an option for only the "Debug"/"Win32" configuration, then wonder for a second what's gone wrong when I get errors after switching to the "Release" configuration or "x64".


For problems like this I use ProcessMonitor, a free utility from Microsoft. Among other things, it logs accesses to files. Filter on blah.h, see what path Visual Studio is really using, then adjust your "Additional Includes" as needed.


Ok here was my problem and the solution I came up with:

I have a multi-project solution in VS2003. In one project I have a templated class Child defined in Bar.h which inherits from a non-templated class Parent in Foo.h. Parent has a static member some_mutex declared in it. This meant that I needed to define some_mutex in Foo.cpp.

The problem arose when I tried to include Bar.h in files in other projects, e.g. other.vcproj. Without adding the include path to Bar.h in other.vcproj I'd get a C1083 error because the compiler couldn't find the definition for Child. But when I added Bar.h's include path to other.vcproj I'd get a LNK2001 error for some_mutex because Foo.cpp was in a different project and was not getting included/compiled. This meant that some_mutex was undefined and that caused the LNK2001 error.

The solution was to put Foo.h, Foo.cpp, and Bar.h in their own project NewProj and create a static library. The other projects that wanted to use the class Child just needed to include NewProj.lib, add the path to NewProj.lib, and add the include path to Bar.h.


If you have entered the path to the "blah.h" directory as a relative path, be aware that VS2008 interprets those paths relative to the directory holding the .vcproj project file. So you'll need to work out what that would be.

If your C++ file is "C:\myprogram\source\foo.cpp" and your include file is "C:\myprogram\includes\blah.h", it is not adequate to provide an include path of "..\includes". You have to figure out where your project file is. If it's "C:\myprogram\build\mysolution\myprogram\myprogram.vcproj" then the include path must be "..\..\..\includes".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜