使用Qt/qmake时如何将生成的文件(例如目标文件)放入单独的文件夹中?
我有一个使用 qmake 的 Qt 项目。为了提高清晰度和可读性,我想将
- 源文件
- 构建系统
- 生成的文件(例如目标文件)
分开。
所以我的第一步是将源文件放入 src/ 子目录中:
myproject/
myproject.pro
src/
main.cpp
MainWindow.ui
...
这样我将源文件与构建系统(*.pro)分开。但是,当我运行 qmake
后跟 make
时,生成的文件(目标文件等)将被放入主项目文件夹中:
myproject/
myproject.pro
Makefile
main.o
ui_MainWindow.h
...
src/
main.cpp
MainWindow.ui
...
嗯,至少它们不是放入 src/
文件夹中,但如何指定将它们放入另一个子文件夹(例如 build/
)中?
myproject/
myproject.pro
Makefile
build/
main.o
ui_MainWindow.h
...
src/
main.cpp
MainWindow.ui
...
(顺便说一句,我不关心目标二进制文件 myproject
放在哪里,但我想它应该直接放入项目文件夹中,而不是放入 build/
中。)
I have a Qt project that uses qmake. To improve clarity and readability, I'd like to keep the
- source files
- build system
- generated files (such as object files)
separate.
So my first step was putting the source files into a src/ sub directory:
myproject/
myproject.pro
src/
main.cpp
MainWindow.ui
...
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
...
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
...
(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/
.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将以下行添加到您的
*.pro
文件中:以下位置提供了变量列表:
You can add the following lines to your
*.pro
file:A list of variables is available at the following locations:
https://wiki.qt.io/Undocumented_QMake#Config_features
在*.pro中写入
https://wiki.qt.io/Undocumented_QMake#Config_features
in *.pro write