前几天我在Visual Studio中遇到了一个包括dll的问题,并以为我已经解决了所有问题,但是事实证明我没有。我的问题也很奇怪,因为一种选择有效,而另一种无效。我遇到的行为有些奇怪,但是我会尽力解释。首先,这是我尝试的一些代码(其中一个可行)包括我创建的dll的 header :
#include <QtWidgets/QApplication>
#include <QMainWindow>
/*
This below works; it seems to be stepping backwards out of the
project and into the folder of the dll project.
*/
#include "../ArclightFramework/GameWindow.h" // This works.
/*
Below does not work, even though the path has been set in the
additional directories field of the project. Oddly, though, I
do get intellisense for the path the below.
*/
#include "ArclightEngine/ArclightFramework/GameWindow.h" // Does not work.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
GameWindow f;
f.show();
return a.exec();
}
第一个include作品非常完美,我可以将所有将来的作品都包含在内。但是,有人知道为什么第二个include无效吗?这就是我所说的“不起作用”。
1>------ Build started: Project: ArclightEngine, Configuration: Debug Win32 ------
1> main.cpp
1>main.cpp(13): fatal error C1083: Cannot open include file: 'ArclightEngine/ArclightFramework/GameWindow.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
这甚至是同一只鼠标悬停在错误上方的图片:
您会发现,很奇怪的是,我DID包含了“其他导入目录”的路径;这是一张图片:
这是该目录,以及显示应该正确找到所有内容的完整路径。
我的问题很简单。为什么Visual Studio无法找到包含文件?
更新:这是另一张图片,显示Intellisense如何提供包含路径的完成,但是同样,此后它不起作用!
另一个更新:
好吧,所以我尝试了一些新东西。这次,我没有将绝对路径添加到“其他包含”字段中,而是添加了:“$(ProjectDir)../../” Intellisense再次为该路径及其中的 header 提供完成。但是之后它不能识别文件本身,但是它们确实存在并且路径是完美的。使用上面的宏,我的路径会将我的包含路径转换为:
"ArclightEngine/ArclightFramework/BLAH.h"
这是一张新图片,显示了我包含的路径:
我不明白我所做的和正在工作的路径之间的区别是
"#include "../ArclightFramework/GameWindow.h""
另外,显然,此包含路径现在也适用:
"#include "/Users/Krynn/Desktop/ArclightEngine/ArclightEngine/ArclightFramework/GameWindow.h""
TL; DR
我想要的是能够键入“#include“ArclightEngine / ArclightFramework / blah.h”
最佳答案
您说的用户包括:
C:\Users\Krynn\Desktop\ArclightEngine
您正在尝试包括:
"ArclightEngine/ArclightFramework/GameWindow.h"
因此,VS尝试使用引号而不是尖括号时的第一个路径是:
C:\Users\Krynn\Desktop\ArclightEngine\ArclightEngine\ArclightFramework\GameWindow.h
这只是两条路径加在一起,所以永远都行不通。
因此包括:
"../ArclightEngine/ArclightFramework/GameWindow.h"
成为:
C:\Users\Krynn\Desktop\ArclightEngine\..\ArclightEngine\ArclightFramework\GameWindow.h
变成:
C:\Users\Krynn\Desktop\ArclightEngine\ArclightFramework\GameWindow.h
因此,这有效。因此,另一种选择应该包括:
ArclightFramework\GameWindow.h
更新:
看来您真正的问题是您更新了“发布Win32”的配置,但是在其中构建具有不同设置的“调试Win32”。更新适用于所有配置和平台(例如包含路径)的设置时,请确保从组合框中选择“所有配置”和“所有平台”。
关于c++ - Visual Studio包含dll子项目标题问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27211829/