在 Qt 源代码树之外构建 Qt 应用程序
我制作了一个基于 Qt 示例应用程序的简单 Qt 应用程序,并在 Qt 源代码树的“examples”目录中构建良好。
现在我想将项目文件移动到其他位置,但 qmake 无法创建可以找到 Qt 头文件的 Makefile。
项目文件已从 ~/qt-everywhere-opensource-src-4.7.2/examples/webkit/fullscreenbrowser
移动到 ~/cvswork/fullscreenbrowser/
因此 < strong>.pro 文件现在是 ~/cvswork/fullscreenbrowser/fullscreenbrowser.pro
并且 Qt 源代码仍然位于~/qt-everywhere-opensource-src-4.7.2
qmake
本身运行良好,但 make
无法加载一些包含:
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_WEBKIT_LIB
-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB
-I/usr/share/qt4/mkspecs/linux-g++
-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork
-I/usr/include/qt4/QtGui
-I/usr/include/qt4/QtWebKit
-I/usr/include/qt4
-I.
-o main.o main.cpp
main.cpp:41:17: error: QtGui: No such file or directory
作为比较,在 ...examples... 目录下构建时,第一个 g++
调用有很大不同:
$ make
g++ -c -pipe -fno-exceptions -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG
-DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX
-DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_HAVE_SSE3
-DQT_HAVE_SSSE3 -DQT_HAVE_SSE4_1 -DQT_HAVE_SSE4_2 -DQT_HAVE_AVX -DQT_SHARED
-I../../../mkspecs/qws/linux-x86-g++
-I.
-I../../../include/QtCore
-I../../../include/QtNetwork
-I../../../include/QtGui
-I../../../include/QtWebKit
-I../../../include
-I.moc/release-shared-emb-x86
-o .obj/release-shared-emb-x86/main.o main.cpp
我必须配置什么才能找到 Qt 源目录?
编辑: fullscreenbrowser.pro
文件可以在此处查看:http:// /pastebin.com/jUPJiWBC
EDIT2: 将 -nocache
添加到 qmake
调用时,我在示例目录中得到相同的行为。
I made a simple Qt application that's based on an Qt example application and builds fine from within the "examples" directory of the Qt sourcetree.
Now I want to move my project files to a different location but qmake fails to create a Makefile that can find the Qt header files.
The project files have been moved from ~/qt-everywhere-opensource-src-4.7.2/examples/webkit/fullscreenbrowser
to ~/cvswork/fullscreenbrowser/
So the .pro file is now ~/cvswork/fullscreenbrowser/fullscreenbrowser.pro
And the Qt sources are still at ~/qt-everywhere-opensource-src-4.7.2
qmake
itself runs fine, but make
fails to load some includes:
$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_WEBKIT_LIB
-DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB
-I/usr/share/qt4/mkspecs/linux-g++
-I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork
-I/usr/include/qt4/QtGui
-I/usr/include/qt4/QtWebKit
-I/usr/include/qt4
-I.
-o main.o main.cpp
main.cpp:41:17: error: QtGui: No such file or directory
For comparison, when building under the ...examples... directory, the first g++
call is much different:
$ make
g++ -c -pipe -fno-exceptions -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG
-DQT_WEBKIT_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX
-DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_HAVE_SSE3
-DQT_HAVE_SSSE3 -DQT_HAVE_SSE4_1 -DQT_HAVE_SSE4_2 -DQT_HAVE_AVX -DQT_SHARED
-I../../../mkspecs/qws/linux-x86-g++
-I.
-I../../../include/QtCore
-I../../../include/QtNetwork
-I../../../include/QtGui
-I../../../include/QtWebKit
-I../../../include
-I.moc/release-shared-emb-x86
-o .obj/release-shared-emb-x86/main.o main.cpp
What do i have to configure so that the Qt source directory is found?
EDIT: The fullscreenbrowser.pro
file can be seen here: http://pastebin.com/jUPJiWBC
EDIT2: I get the same behavior in the examples directory when adding -nocache
to the qmake
call.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这实际上或多或少是有意设计的。在源文件夹内构建需要与针对已安装的树进行构建有所不同,例如,为了能够理智地进行升级(就地预构建所有内容,而不引用任何现有构建)。
我相信“技巧”是通过顶级源文件夹中的特定
.qmake.cache
文件完成的(~/qt-everywhere-opensource-src-4.7.2
您的案例)是在配置源代码树(恰好在其中构建qmake
)时创建的。尝试将该文件复制到新的构建位置(
~/cvswork/fullscreenbrowser/
或~/cvswork
如果您有其他项目,它也应该在那里查找),然后重新运行qmake(确保使用Qt源目录中的qmake)。如果您只是配置了源树,这应该可以工作。
这是解压并配置旧 Qt 存档后,我的计算机上的
.qmake.cache
文件的第一行:如您所见,许多基本的
qmake
变量被该构建树前缀覆盖。(不知道为什么你不简单地将 Qt 安装在你的主目录中的某个地方。你不会有任何这些痛苦,而且你不需要
root
我认为 只要前缀是你自己的 - 虽然已经很久没有尝试过了,所以 YMMV。)That's actually more or less by design I think. Building inside the source folder needs to be a bit different than building against an installed tree, just to be able to do upgrades sanely for instance (prebuild everything in-place without referencing any existing build).
I believe that "trick" is done with a specific
.qmake.cache
file in the toplevel source folder (~/qt-everywhere-opensource-src-4.7.2
in your case) that is created when you configure the source tree (which happens to buildqmake
in there).Try copying that file to your new build location (
~/cvswork/fullscreenbrowser/
or~/cvswork
if you have other projects, it should look there too), and re-runqmake
(making sure you use the one inside the Qt source directory).This should work if you've simply configured the source tree.
Here's the first lines of that
.qmake.cache
file on my machine after having unpacked and configured an old Qt archive:As you can see, a lot of the fundamental
qmake
variables are overridden with that build tree prefix.(Not sure why you don't simply install Qt somewhere in your home directory. You wouldn't have any of this pain, and you don't need
root
for that I think as long as the prefix is your own - haven't tried that in ages though, so YMMV.)该示例可能尝试包含层次结构中其他位置的文件。对于简单的情况,您通常可以生成一个新的项目文件,如下所示:
qmake
将递归地检查您的目录并包含文件。它不够聪明,无法弄清楚所有事情,比如您可能需要的每个模块,但它在简单的测试项目上做得很好。我通常会对我的所有尖峰执行上述操作。The example probably attempts to include a file from elsewhere in the hierarchy. For simple cases you can often generate a new project file as follows:
qmake
will go through your directory recursively examining and including files. It's not smart enough to figure out everything, like every module you may need, but it does a good job on simple test projects. I usually do the above for all my spikes.