qmake无法定位任何源文件或头文件。

时间:2022-06-21 22:13:50

I am trying to bring my project from one computer with qt4 to another where I freshly installed qt5 and I am having a very strange problem.

我正试图把我的项目从一台带有qt4的电脑带到另一台刚刚安装了qt5的电脑,我遇到了一个非常奇怪的问题。

The qmake suddenly cannot find any of my source or header files.

qmake突然找不到我的源文件或头文件。

Here is a minimalist example:

这里有一个极简主义者的例子:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

INCLUDEPATH += $$PWD/Dir/
DEPENDPATH += $$PWD/Dir/

HEADERS  += mainwindow.h \
    f.h \

FORMS    += mainwindow.ui

Where Dir/f.h exists in the same directory as untitled.pro. And I get this output from qmake:

Dir / f。h与untitled.pro存在于同一个目录中。我从qmake得到这个输出:

05:18:45: Starting: "/opt/QtSDK/5.0.2/gcc/bin/qmake" 
/home/martin/Projects/untitled/untitled.pro 
-r -spec linux-g++ CONFIG+=debug CONFIG+=declarative_debug CONFIG+=qml_debug
WARNING: Failure to find: f.h
05:18:45: The process "/opt/QtSDK/5.0.2/gcc/bin/qmake" exited normally.

I have absolutely no idea what is causing this. What could be the problem?

我完全不知道是什么引起的。有什么问题呢?

EDIT:

编辑:

When I manually prepend the name like this:

当我像这样手工预写名字时:

HEADERS += Dir/f.h \

qmake doesn't complain.

qmake不抱怨。

2 个解决方案

#1


6  

The Same issue solved when I include VPATH in pro file

当我在pro文件中包含VPATH时,同样的问题也解决了

Eg: VPATH += ../../libraries/ INCLUDE += ../../libraries/

例如:VPATH + = . . / . ./图书馆/包括+ = . . / . . /图书馆/

Also with qt 5 we need not to include DEPENDPATH in pro files

同样,在qt5中,我们不需要在pro文件中包含DEPENDPATH

#2


4  

You never defined PWD. The double-dollar sign '$$' prefix indicates a qmake variable defined earlier in the pro file. In your case, the $$PWD portion is completely unnecessary. If you remove it entirely, everything should compile just fine.

你永远不会PWD定义。$$前缀的双美元符号表示在pro文件早期定义的qmake变量。在您的情况下,$PWD部分完全没有必要。如果您完全删除它,那么所有的内容都应该很好地编译。

Edit: Additionally, they quietly changed DEPENDPATH behavior in Qt 5. As of Qt 5, qmake now defaults to using your INCLUDEPATHs when looking for the SOURCES and HEADERS (config += depend_includepath). Simply drop the DEPENDPATH line and you should be good.

编辑:另外,他们悄悄地改变qt5中的依赖路径行为。从Qt 5开始,qmake现在默认使用包含符来查找源和头(config += depend_includepath)。只需删除依赖路径行,您就应该做得很好。

INCLUDEPATH += "Dir"

Reference: Qmake variables in .pro files

引用:Qmake变量在.pro文件中

#1


6  

The Same issue solved when I include VPATH in pro file

当我在pro文件中包含VPATH时,同样的问题也解决了

Eg: VPATH += ../../libraries/ INCLUDE += ../../libraries/

例如:VPATH + = . . / . ./图书馆/包括+ = . . / . . /图书馆/

Also with qt 5 we need not to include DEPENDPATH in pro files

同样,在qt5中,我们不需要在pro文件中包含DEPENDPATH

#2


4  

You never defined PWD. The double-dollar sign '$$' prefix indicates a qmake variable defined earlier in the pro file. In your case, the $$PWD portion is completely unnecessary. If you remove it entirely, everything should compile just fine.

你永远不会PWD定义。$$前缀的双美元符号表示在pro文件早期定义的qmake变量。在您的情况下,$PWD部分完全没有必要。如果您完全删除它,那么所有的内容都应该很好地编译。

Edit: Additionally, they quietly changed DEPENDPATH behavior in Qt 5. As of Qt 5, qmake now defaults to using your INCLUDEPATHs when looking for the SOURCES and HEADERS (config += depend_includepath). Simply drop the DEPENDPATH line and you should be good.

编辑:另外,他们悄悄地改变qt5中的依赖路径行为。从Qt 5开始,qmake现在默认使用包含符来查找源和头(config += depend_includepath)。只需删除依赖路径行,您就应该做得很好。

INCLUDEPATH += "Dir"

Reference: Qmake variables in .pro files

引用:Qmake变量在.pro文件中