未找到包括 <QtCore/qglobal.h>

Not found include <QtCore/qglobal.h>

所以我正在尝试使用 QT Creator 创建一个 dll。我去了new project -> libary -> C++ libary -> choose。它自动生成了一个带有 global 前缀的 header 文件和一个无法找到的包含 header:

#include <QtCore/qglobal.h>

报错:

error: QtGlobal: No such file or directory

我发现这个 header 被包含在内是为了使用 Q_DECL_EXPORT 宏,所以我搜索了它的定义位置:here。所以我做了 #include <QtGlobal> header 但得到了同样的错误。

错误的来源是什么?我该如何解决?

您可能需要将以下内容添加到您的 *.pro 文件中:

QT += core

找到解决方案!

QT 创建者在 .pro 文件中使用以下行创建了项目:

 QT -= core gui 

注意 -= 运算符,这阻止了 core 库的链接,然后未找到 #include <QtCore/qglobal.h> 只是从该行中删除了 core 并编译很好。

QT 创建者在 .pro 文件中使用以下行创建了项目: 我不得不 remove/commented 使用 # 下面的整行

# QT -= core gui 

在系统环境变量中添加一个QTDIR,重启VS并在VS项目配置中引用$(QTDIR)

enter image description here enter image description here