在 Qt 源代码树之外构建 Qt 应用程序

发布于 2024-11-16 02:42:46 字数 1875 浏览 1 评论 0原文

我制作了一个基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风轻花落早 2024-11-23 02:42:46

我认为这实际上或多或少是有意设计的。在源文件夹内构建需要与针对已安装的树进行构建有所不同,例如,为了能够理智地进行升级(就地预构建所有内容,而不引用任何现有构建)。

我相信“技巧”是通过顶级源文件夹中的特定 .qmake.cache 文件完成的(~/qt-everywhere-opensource-src-4.7.2您的案例)是在配置源代码树(恰好在其中构建qmake)时创建的。

尝试将该文件复制到新的构建位置(~/cvswork/fullscreenbrowser/~/cvswork 如果您有其他项目,它也应该在那里查找),然后重新运行qmake(确保使用Qt源目录中的qmake)。

如果您只是配置了源树,这应该可以工作。

这是解压并配置旧 Qt 存档后,我的计算机上的 .qmake.cache 文件的第一行:

CONFIG +=  release shared dll largefile stl precompile_header mmx 3dnow sse sse2 sse3 ssse3 sse4_1 sse4_2 avx dylib create_prl link_prl depend_includepath fix_output_dirs QTDIR_build
QT_SOURCE_TREE = $quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_TREE = $quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_PARTS = libs tools examples demos docs translations
QMAKE_ABSOLUTE_SOURCE_ROOT = $QT_SOURCE_TREE
QMAKE_MOC_SRC    = $QT_BUILD_TREE/src/moc

#local paths that cannot be queried from the QT_INSTALL_* properties while building QTDIR
QMAKE_MOC        = $QT_BUILD_TREE/bin/moc
QMAKE_UIC        = $QT_BUILD_TREE/bin/uic
QMAKE_UIC3       = $QT_BUILD_TREE/bin/uic3
QMAKE_RCC        = $QT_BUILD_TREE/bin/rcc
QMAKE_QDBUSXML2CPP = $QT_BUILD_TREE/bin/qdbusxml2cpp
QMAKE_INCDIR_QT  = $QT_BUILD_TREE/include
QMAKE_LIBDIR_QT  = $QT_BUILD_TREE/lib

QMAKE_LFLAGS    = -Wl,-rpath-link,$QT_BUILD_TREE/lib $QMAKE_LFLAGS
QT_CFLAGS_PSQL   = -I/usr/include/postgresql-8.4
QT_LFLAGS_PSQL   = -L/usr/lib64/postgresql-8.4/lib64
QT_CFLAGS_MYSQL   = -I/usr/include/mysql
QT_LFLAGS_MYSQL   = -Wl,-O1 -Wl,--as-needed -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -L/usr//lib64 -lz -lpthread -lcrypt -lnsl -lm -lpthread -L/usr/lib64/ -lssl -lcrypto
Q    T_LFLAGS_ODBC   = -lodbc
QMAKESPEC = $QT_BUILD_TREE/mkspecs/linux-g++-64
...

如您所见,许多基本的 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 build qmake 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-run qmake (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:

CONFIG +=  release shared dll largefile stl precompile_header mmx 3dnow sse sse2 sse3 ssse3 sse4_1 sse4_2 avx dylib create_prl link_prl depend_includepath fix_output_dirs QTDIR_build
QT_SOURCE_TREE = $quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_TREE = $quote(/home/foo/src/qt-everywhere-opensource-src-4.7.3)
QT_BUILD_PARTS = libs tools examples demos docs translations
QMAKE_ABSOLUTE_SOURCE_ROOT = $QT_SOURCE_TREE
QMAKE_MOC_SRC    = $QT_BUILD_TREE/src/moc

#local paths that cannot be queried from the QT_INSTALL_* properties while building QTDIR
QMAKE_MOC        = $QT_BUILD_TREE/bin/moc
QMAKE_UIC        = $QT_BUILD_TREE/bin/uic
QMAKE_UIC3       = $QT_BUILD_TREE/bin/uic3
QMAKE_RCC        = $QT_BUILD_TREE/bin/rcc
QMAKE_QDBUSXML2CPP = $QT_BUILD_TREE/bin/qdbusxml2cpp
QMAKE_INCDIR_QT  = $QT_BUILD_TREE/include
QMAKE_LIBDIR_QT  = $QT_BUILD_TREE/lib

QMAKE_LFLAGS    = -Wl,-rpath-link,$QT_BUILD_TREE/lib $QMAKE_LFLAGS
QT_CFLAGS_PSQL   = -I/usr/include/postgresql-8.4
QT_LFLAGS_PSQL   = -L/usr/lib64/postgresql-8.4/lib64
QT_CFLAGS_MYSQL   = -I/usr/include/mysql
QT_LFLAGS_MYSQL   = -Wl,-O1 -Wl,--as-needed -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -L/usr//lib64 -lz -lpthread -lcrypt -lnsl -lm -lpthread -L/usr/lib64/ -lssl -lcrypto
Q    T_LFLAGS_ODBC   = -lodbc
QMAKESPEC = $QT_BUILD_TREE/mkspecs/linux-g++-64
...

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.)

暗藏城府 2024-11-23 02:42:46

该示例可能尝试包含层次结构中其他位置的文件。对于简单的情况,您通常可以生成一个新的项目文件,如下所示:

qmake -project # generate a project file using defaults
qmake          # generate a makefile from the project file
make           # build using the makefile

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 -project # generate a project file using defaults
qmake          # generate a makefile from the project file
make           # build using the makefile

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文