简体   繁体   English

Visual Studio 2010中的“其他包含目录”不起作用

[英]'Additional include directories' in visual studio 2010 doesn't work

I am banging my head on this one for a while so I figure I will post. 我在这上面敲了一下头,所以我认为我会发布。 I have two library projects where Project2 uses/references Project1 in the following directory structure. 我有两个库项目,其中Project2在以下目录结构中使用/引用Project1。

c:\code\Library\Project1
c:\code\Library\Project2

Both are library projects. 两者都是图书馆项目。 I have included the path in Project2 at Properties>Configuration Properties>C/C++>General>'Additonal Include Directories'. 我已经在Project2的“属性”>“配置属性”>“ C / C ++”>“常规”>“附加包含目录”中包含了该路径。 It reads ..\\Project1; %(AdditionalIncludeDirectories) 读取..\\Project1; %(AdditionalIncludeDirectories) ..\\Project1; %(AdditionalIncludeDirectories)

Now there is a file in Project2 which #includes file that is present in project1 folder. 现在Project2中有一个文件,其中的#includes文件存在于project1文件夹中。 Inspite of having included the path as above it still comes up with an error: 尽管已包含上述路径,但仍会出现错误:

1>c:\code\Library\Project2\MyTestDlg.cpp(6): fatal error C1083: Cannot open include file: 'GraphCtrl.h': No such file or directory

The weird thing is that similar setting works if I don't change the original project names. 奇怪的是,如果我不更改原始项目名称,则类似的设置会起作用。 The projects are originally in folder where they link fine. 这些项目最初位于它们可以正常链接的文件夹中。

c:\code\Library\Project1 1.0.0
c:\code\Library\Project2 1.0.0

What I am doing is removing the last version names from the project folders (and relink them together again) but this has become a nightmare! 我正在做的是从项目文件夹中删除最新版本名称(然后再次将它们重新链接在一起),但这已成为噩梦! Any suggestions? 有什么建议么?

ps I did research on this quite a bit and it seems like has to do with length of the directories but I think I am well with in limits. ps我对此进行了很多研究,似乎与目录的长度有关,但我认为我在限制方面做得很好。 The fact that previously longer folder names work and short doesn't, it shows lengths are not the issue. 以前较长的文件夹名称有效而较短的文件夹名称无效,这表明长度不是问题。

Addon: 添加在:

The following is the actual error I am getting with actual file names: One of the problem is that somehow it still references the old library with full name GraphCtrlLib 1.0.0.0 even though I have completely removed it and can't find any more reference of it. 以下是我在使用实际文件名时遇到的实际错误:问题之一是,尽管我已完全删除它并找不到更多参考,但它仍以某种方式仍引用全名GraphCtrlLib 1.0.0.0的旧库。它。 I this it probably is not related to this error though. 我这可能与这个错误无关。

1>Build started 12/11/2012 5:16:02 PM.
1>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(1200,9): warning : The referenced project '..\Graph\Graph.vcxproj' does not exist.
1>InitializeBuildStatus:
1>  Touching "Debug\ViewerLib.unsuccessfulbuild".
1>ClCompile:
1>  All outputs are up-to-date.
1>  OpenViewerDlg.cpp
1>c:\code\libraries\viewerlib\viewerdlg.cpp(6): fatal error C1083: Cannot open include file: 'GraphCtrl.h': No such file or directory

Finally fixed the problem. 终于解决了问题。 I opened the .vcxproj file in notepad and changed all reference of old path to new path and saved it. 我在记事本中打开.vcxproj文件,并将所有旧路径的引用更改为新路径并保存。 That fixed the problem. 这解决了问题。

It was caused by the fact that the project file was read only and VC2010 was not updating it properly. 原因是项目文件是只读的,而VC2010未正确更新它。 I kept making the changes in project properties and I could tell by reading back that they are as I wanted them but when I closed the project and load it back, it was back to what was before change. 我一直在项目属性中进行更改,通过回读它们可以告诉我它们想要的状态,但是当我关闭项目并将其加载回时,它又回到了更改之前的状态。 So the changes were never getting applied. 因此,这些更改从未得到应用。 VS2010 didn't tell me that it can't save or apply the changes but would accept them and never apply them! VS2010并没有告诉我它无法保存或应用更改,但是会接受它们,永远不会应用它们!

I realize it's an old topic, but thought I'd add my solution in case future searchers have the same specific scenario. 我意识到这是一个老话题,但是我想我会添加解决方案,以防将来的搜索者有相同的特定情况。

In my case the additional include directory was defined as a User Macro in a Property Page (accessed via View, Property Manager, then right click on the project, Properties). 在我的情况下,附加的包含目录被定义为属性页中的用户宏(可通过“视图”,“属性管理器”访问,然后右键单击项目“属性”)。 But although the value was updated there, the property page was not actually saved (even though the C++, Command Line property showed the correct path (!)). 但是,尽管在那里更新了值,但实际上并未保存该属性页(即使C ++命令行属性显示了正确的路径(!))。 Had to check out the .props file from source control and save it, then rebuild - finally the include files in that directory are found. 必须从源代码管理中检出.props文件并保存,然后进行重建-最终找到该目录中的包含文件。

Adding this answer, just in case someone else needs it. 添加此答案,以防万一其他人需要它。 I had the same problem in VS 2015. 我在VS 2015中遇到了同样的问题。

I solved it by editing the .vcxproj file. 我通过编辑.vcxproj文件解决了该问题。

In it I search for "path" 我在其中搜索“路径”

Then add your include directory path to it. 然后向其中添加您的包含目录路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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