QtCore/QtGlobal : No such file or directory

标签 qt

我正在尝试构建两个库:一个是静态的,一个是共享的。问题出在静态库上。我有以下文件夹:

src/
  db/
    dbal.h
    dbal.pro
  dll/
    Distribution.h
    dll.pro
  project.pro

db 是静态的,dll 是共享的

Distribution.h:

#ifndef DISTRIBUTION_H_
#define DISTRIBUTION_H_

#include <QtCore/QtGlobal>

#if defined(BUILDING_DLL)
#define DLL_FUNCTION Q_DECL_EXPORT
#else
#define DLL_FUNCTION Q_DECL_IMPORT
#endif

#endif /* DISTRIBUTION_H_ */

现在这里是 db/中的文件,其中包含 Distribution.h

dbal.h

#ifndef DBAL_H_
#define DBAL_H_

#include "Distribution.h"

...

#endif

db.pro:

TARGET = db
TEMPLATE = lib
CONFIG = staticlib c++11

QT += core

INCLUDEPATH += ../dll

HEADERS += dbal.h
HEADERS += dbal_sqlite.h

SOURCES += dbal.cpp
SOURCES += dbal_sqlite.cpp

######################################################################
# Build to custom directories
######################################################################

DESTDIR = ../../build/debug/db

OBJECTS_DIR = $$DESTDIR/.obj
MOC_DIR = $$DESTDIR/.moc
RCC_DIR = $$DESTDIR/.qrc
UI_DIR = $$DESTDIR/.ui

当我在 db/文件夹中运行 make 时,出现以下错误:QtCore/QtGlobal:没有这样的文件或目录。似乎还缺少 -I 命令。

这是我的日志:

make all 
cd src/db/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake /mnt/record/_dev/linux/projects/cdt/wasp/src/db/db.pro -o Makefile ) && make -f Makefile all
make[1]: Entering directory `/mnt/record/_dev/linux/projects/cdt/wasp/src/db'
g++ -c -m64 -pipe -O2 -std=c++0x  -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I../dll -o ../../build/debug/db/.obj/dbal.o dbal.cpp
In file included from dbal.h:9:0,
                 from dbal.cpp:3:
../dll/Distribution.h:4:27: fatal error: QtCore/QtGlobal: No such file or directory
 #include <QtCore/QtGlobal>
                           ^
compilation terminated.

最佳答案

注意日志:

g++ -c -m64 -pipe -O2 -std=c++0x -I/usr/share/qt5/mkspecs/linux-g++-64 -I. -I../dll -o ../../build/debug/db/.obj/dbal.o dbal.cpp

显示包括提供给 g++ 的路径,不包括到 QtCore/QtGlobal 的路径。

解决方法是.pro文件需要

CONFIG = staticlib c++11

将更改为:

CONFIG += staticlib c++11

具体来说,CONFIG = ... 行从配置中删除 qt 元素,因此您的项目既不包括也不链接 Qt 文件。

关于QtCore/QtGlobal : No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24517702/

相关文章:

c++ - 我正在尝试使用官方 Qt 4.8 文档中的 QTabBar::pane 样式表

c++ - QTableView高级选择

c++ - QString 到 windows BYTE

c++ - 输出 QProcess readAll 对标签的响应

windows - 使用 CMake 在 Windows 上静态链接 Qt

c++ - QPrinter 分辨率在 Linux 中是错误的

c++ - 为 Qt 项目创 build 置

c++ - C++ 的 Qt 超链接

c++ - 混合 C/C++ 代码产生 "undefined symbol"与共享库

c++ - Qt 5.2.1 无法在 mac OSX 10.8.5 上构建