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

前端 未结 3 1281
无人共我
无人共我 2020-12-18 18:10

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;
}

na         


        
相关标签:
3条回答
  • 2020-12-18 18:56

    Depending on what you are trying to build, you may be able to use the subdirs template in qmake to do this. You'll need to put a project file in each of your namespace directories, and in this you can specify different output directories for your object files.

    -->src/main.pro
      -->namespace1/n1.pro
        -->someclass.cpp
      -->namespace2/n2.pro
        -->someclass.cpp
    

    main.pro:

    TEMPLATE = subdirs
    SUBDIRS  = namespace1 namespace2
    

    n1.pro and n2.pro:

    include("../common.pri")
    OBJECTS_DIR = $${PWD}
    TARGET = some_target
    TEMPLATE = some_qmake_template
    

    common.pri: configurations common to both projects.

    0 讨论(0)
  • Concerning your fears that CMake might be too complicated: I have been working on projects using both build systems. While I agree that qmake is probably easier to begin with, CMake definitely has its merits, too:

    • It makes out-of-source builds very easy. Just execute cmake <Path to source> in your build directory. This is great when your sources are on an NFS share, for example, and you want the object files to be placed on a local file system.

    • Its support for finding additional libraries is very powerful. Lots of FindXXX.cmake files are already shipped with your CMake distribution, making the inclusion of "heavy" libraries such as OpenCV as easy as FIND_PACKAGE(OpenCV REQUIRED).

    • It even has out-of-the-box support for Qt. In fact, I use it for a larger software project where Qt is used for the GUI part. We decided on CMake because we required platform independence and multiple libraries which we could not easily add via qmake.

    All in all, use the build system you are comfortable with (as long as your build system does not inhibit your software development).

    0 讨论(0)
  • 2020-12-18 18:59

    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

    0 讨论(0)
提交回复
热议问题