使用Qt/qmake时如何将生成的文件(例如目标文件)放入单独的文件夹中? [英] How to put generated files (e.g. object files) into a separate folder when using Qt/qmake?
问题描述
我有一个使用qmake的Qt项目.为了提高清晰度和可读性,我想保留
I have a Qt project that uses qmake. To improve clarity and readability, I'd like to keep the
- 源文件
- 构建系统
- 生成的文件(例如目标文件)
分开.
所以我的第一步是将源文件放入src/子目录:
So my first step was putting the source files into a src/ sub directory:
myproject/
myproject.pro
src/
main.cpp
MainWindow.ui
...
这样,我从构建系统(* .pro)中分离了源文件.但是,当我随后依次运行qmake
和make
时,生成的文件(目标文件等)将放置在主项目文件夹中:
That way I separated the source files from the build system (*.pro). However, when I then run qmake
followed by make
, the generated files (object files, etc) are placed into the main project folder:
myproject/
myproject.pro
Makefile
main.o
ui_MainWindow.h
...
src/
main.cpp
MainWindow.ui
...
好吧,至少它们没有放入src/
文件夹中,但是如何指定将它们放入另一个子文件夹中,例如build/
?
Well, at least they weren't put into the src/
folder, but how do I specify that they are put into another sub folder such as build/
?
myproject/
myproject.pro
Makefile
build/
main.o
ui_MainWindow.h
...
src/
main.cpp
MainWindow.ui
...
(顺便说一句,我不在乎目标二进制文件myproject
放在何处,但我想应该将其直接放置在项目文件夹中而不是build/
中.)
(BTW, I don't care where the target binary myproject
is put, but I guess it should be placed directly into project folder rather than into build/
.)
推荐答案
您可以将以下行添加到您的*.pro
文件中:
You can add the following lines to your *.pro
file:
DESTDIR=bin #Target file directory
OBJECTS_DIR=generated_files #Intermediate object files directory
MOC_DIR=generated_files #Intermediate moc files directory
在以下位置可以找到变量列表:
A list of variables is available at the following locations:
- Qt 4.8
- Qt 5
这篇关于使用Qt/qmake时如何将生成的文件(例如目标文件)放入单独的文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!