如何指示 Qt Creator PRO 文件在单独的文件夹中输出 *.o 文件和 moc_* 文件?

发布于 2024-11-10 16:51:45 字数 83 浏览 4 评论 0原文

目前,QtCreator 在应用程序的根文件夹中创建 .o 和 moc_ 文件。如何指示项目文件将它们放入名为“obj”的子文件夹中?

Currently QtCreator creates .o and moc_ files in the root folder of the application. How I can instruct the project file to put them in a subfolder called "obj"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

上课铃就是安魂曲 2024-11-17 16:51:45

您可以使用 OBJECTS_DIR 和 MOC_DIR 变量来实现此目的。例如,Qt 本身在构建时会执行类似的操作:

OBJECTS_DIR = .obj
MOC_DIR     = .moc

在这种情况下,我认为 .obj、.moc 目录是相对于包含 Makefile 的目录的。

You can use the OBJECTS_DIR and MOC_DIR variables for this. e.g. Qt itself does something like this while building:

OBJECTS_DIR = .obj
MOC_DIR     = .moc

In this case I think the .obj, .moc directories are relative to the directory containing the Makefile.

極樂鬼 2024-11-17 16:51:45

为了保持主(源)文件夹中没有二进制文件和生成的文件,您可以将以下几行放入“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
}

上述设置意味着以下目录结构:

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)

如果不存在,将自动创建最后 3 个目录存在。

这种模式的优点是:

a.您可以将您的项目(myapp 目录)移动到另一个父目录,由于 bin & 的相对规范,它将继续构建正常。构建目录

B.您可以在 myprojects/source/c 下添加更多子项目

。您可以备份(例如 ZIP)所有 myprojects/source/ 目录,而不包含任何二进制文件或生成的文件

To keep your main (source) folder clean of binary and generated files you can put the following lines in your "myapp.pro" file:

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.

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

b. You can add more sub-projects under myprojects/source/

c. You can backup (e.g. ZIP) all of myprojects/source/ directory without including any binary or generated files

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