为什么qmake将所有对象(.o)文件放到一个目录? [英] Why does qmake put all object (.o) files to one directory?

查看:1321
本文介绍了为什么qmake将所有对象(.o)文件放到一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Qt应用程序,在两个不同的命名空间中有两个具有相同名称的类:

Let's say I have a Qt application where I have two classes with the same name in two different namespaces:

namespace namespace1
{
    class SomeClass;
}

namespace namespace2
{
    class SomeClass;
}

我有一个项目目录结构:

and I have a project directory structure according to it:

-->src/
  -->namespace1/
    -->someclass.cpp
  -->namespace2/
    -->someclass.cpp

应用程序使用qmake,它将所有对象(.o)文件放到一个目录 - 所以它创建 someclass.o 文件,然后它重写它与第二个 someclass.o - 这是一个名称冲突,所以它是坏的。

When I compile the application with qmake, it puts all object (.o) files to one directory - so it creates someclass.o file first and then it rewrites it with the second someclass.o - which is a name collision so it is bad.

为什么qmake不考虑源文件的目录结构,为什么不创建 namespace1_someclass.o namespace2_someclass.o

Why does qmake not take into account the directory structure of the source files and why does it not create something like namespace1_someclass.o and namespace2_someclass.o?

是的,我可以将我的类放到一个目录, > namespace1_someclass.cpp 和 namespace2_someclass.cpp ,并且没有名称冲突,但是这会导致在Qt Creator中查看项目浏览器中的源文件时不便,因为当有很多的项目中的源文件,它的可读性比如果有目录结构,我可以展开或崩溃。

Yes, I can put my classes to one directory and name them namespace1_someclass.cpp and namespace2_someclass.cpp and there will be no name collisions, but this causes little inconvenience while looking at the source files in the project explorer in Qt Creator because when there are lot of source files in the project, it is much less readable than if there was the directory structure which I can expand or collapse.

极端是具有如下的目录结构:

One more extreme is to have the directory structure like this:

-->src/
  -->namespace1/
    -->namespace1_someclass.cpp
  -->namespace2/
    -->namespace2_someclass.cpp

这解决了名称冲突,但它冗余重复命名空间名称,因此也不太容易阅读。

which solves name collision but it redundantly duplicates the namespace names - and therefore again less readable.

为什么qmake没有至少一个选项根据源文件将目标文件放到目录结构中? Qt的创作者没有看到这是一个重要的功能?

Why does qmake not have at least an option to put the object files to the directory structure according to the source files? Do creators of Qt not see that this is an important feature?

还有一件事 - 你可以建议我使用 cmake qmake 但我看到使用cmake 非常困难比qmake和qmake的工作非常好,我目前为止 - 除了目标文件放置。

And one more thing - you could recommend me to use cmake tool instead of qmake but I see the use of cmake much much much more difficult than qmake and qmake does its job excellent for me so far - except object files placement.

推荐答案

您可以使用以下方法将对象文件放在源文件旁边:

You can actually put object files alongside source files by using:

CONFIG + = object_parallel_to_source

CONFIG + = object_with_source

取决于您的qmake版本。

depending on your qmake version.

>资料来源: https://wiki.qt.io/Undocumented_QMake#Config_features

Source: https://wiki.qt.io/Undocumented_QMake#Config_features

这篇关于为什么qmake将所有对象(.o)文件放到一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆