[英]How I can instruct a Qt Creator PRO file to output the *.o files and moc_* files in separate folder?
Currently QtCreator creates .o and moc_ files in the root folder of the application.目前 QtCreator 在应用程序的根文件夹中创建.o 和 moc_文件。 How I can instruct the project file to put them in a subfolder called "obj"?
我如何指示项目文件将它们放在名为“obj”的子文件夹中?
You can use the OBJECTS_DIR
and MOC_DIR
variables for this.您可以为此使用
OBJECTS_DIR
和MOC_DIR
变量。 eg Qt itself does something like this while building:例如 Qt 本身在构建时会执行以下操作:
OBJECTS_DIR = .obj
MOC_DIR = .moc
In this case I think the.obj, .moc directories are relative to the directory containing the Makefile.在这种情况下,我认为.obj、.moc 目录是相对于包含 Makefile 的目录的。
To keep your main (source) folder clean of binary and generated files you can put the following lines in your "myapp.pro" file:为了使您的主(源)文件夹中没有二进制文件和生成的文件,您可以在“myapp.pro”文件中添加以下行:
DESTDIR = ../../bin
UI_DIR = .
CONFIG(debug, debug|release) {
TARGET = myappd
OBJECTS_DIR = ../../build/myapp/debug
MOC_DIR = ../../build/myapp/debug
}
CONFIG(release, debug|release) {
TARGET = myapp
OBJECTS_DIR = ../../build/myapp/release
MOC_DIR = ../../build/myapp/release
}
The above settings imply the following directory structure:上述设置意味着以下目录结构:
myprojects/source/myapp/ => containing myapp.pro + all other project files hpp, cpp etc.
myprojects/bin/ => containing myapp.exe & myappd.exe application files
myprojects/build/myapp/release => object files + moc files (release)
myprojects/build/myapp/debug => object files + moc files (debug)
The last 3 directories will be automatically created if they do not exist.如果最后 3 个目录不存在,将自动创建它们。
The advantages of this schema is:这种模式的优点是:
a.一个。 You can move your project (myapp directory) to another parent directory and it will continue to build OK due to the relative specification of bin & build directories
您可以将您的项目(myapp 目录)移动到另一个父目录,由于 bin 和构建目录的相关规范,它将继续构建 OK
b.湾。 You can add more sub-projects under myprojects/source/
您可以在 myprojects/source/ 下添加更多子项目
c. c。 You can backup (eg ZIP) all of myprojects/source/ directory without including any binary or generated files
您可以备份(例如 ZIP)所有 myprojects/source/ 目录,而不包括任何二进制文件或生成的文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.