C++ 从命令行构建 Qt Creator 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6127357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Building Qt Creator projects from command line
提问by Tamás Szelei
I'm in the process of writing a build script to automate build and release tasks. I have a Qt Creator project which has three configurations, two of which I want to completely rebuild from scratch without any precompiled headers and existing .o files to skip (release and release_production). The latter is the same except it has the PRODUCTION symbol #defined.
我正在编写构建脚本来自动化构建和发布任务。我有一个 Qt Creator 项目,它有三个配置,其中两个我想从头开始完全重建,没有任何预编译的头文件和现有的 .o 文件要跳过(release 和 release_production)。后者是相同的,只是它有生产符号#defined。
I'm using windows. How can I build these configurations from the command line?
我正在使用窗户。如何从命令行构建这些配置?
Edit: Some clarification: The Qt Creator custom build steps are not stored in the qmake makefile but in the Qt Creator-specific .pro.user XML file. I would like to perform these from the command line without repeating them in the script.
编辑:一些说明:Qt Creator 自定义构建步骤未存储在 qmake 生成文件中,而是存储在 Qt Creator 特定的 .pro.user XML 文件中。我想从命令行执行这些而不在脚本中重复它们。
采纳答案by Nam Nguyen
There are two steps involved here:
这里涉及两个步骤:
Running
qmaketo generate Makefiles. The usual command isc:\qt.7.2\bin\qmake.exe" path\to\some\project.pro -r -spec win32-g++ CONFIG+=...The
-specswitch is important. Make sure you supply a valid makespec file.CONFIGneeds to be specified in this step.Running
maketo compile and link. This is easyC:\MinGW32\bin\mingw32-make -f Makefile.DebugRemember to point
maketo the correct makefile.
运行
qmake以生成 Makefile。通常的命令是c:\qt.7.2\bin\qmake.exe" path\to\some\project.pro -r -spec win32-g++ CONFIG+=...该
-spec开关是非常重要的。确保提供有效的 makespec 文件。CONFIG这一步需要指定。运行
make编译和链接。这很简单C:\MinGW32\bin\mingw32-make -f Makefile.Debug请记住指向
make正确的makefile。
回答by vrince
In the project tab of QtCreator you have the exact command, QtCreator runs on build for both debug and release. Just run those lines in a environment your project can be build (Qt console). But basically Qt projects are build with a qmake.exethen a nmake.exeor the Qt multi-thread make-like executable jom.exe.
在 QtCreator 的项目选项卡中,您有确切的命令,QtCreator 在构建时运行,用于调试和发布。只需在可以构建项目的环境中运行这些行(Qt 控制台)。但基本上 Qt 项目是使用qmake.exethen anmake.exe或 Qt multi-thread make-like executable 构建的jom.exe。
For your "production" mode your can use CONFIG+=productionargument in the qmake command, then in your .pro files :
对于您的“生产”模式,您可以CONFIG+=production在 qmake 命令中使用参数,然后在您的 .pro 文件中使用:
CONFIG(production){
DEFINES+=PRODUCTION
}else{
}

