Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

c++ - Why does qmake put all object (.o) files to one directory?

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

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.

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?

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.

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?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

CONFIG += object_parallel_to_source

or

CONFIG += object_with_source

depending on your qmake version.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...