Found, according to rumors, an undocumented configuration qmake , which allows to place object files in separate folders in accordance with the structure of the project itself.

 CONFIG += object_parallel_to_source 

This is necessary when you keep several classes with the same name in different namespaces in order to have the same file name for these classes in different directories (it’s really silly to create different file names each time).

If these classes are not inherited from QObject everything works fine, but in the opposite case qmake creates moc_ClassName (.cpp .h) files for which the rule for object files does not work, that is, everything is thrown into one directory.

Suppose we created two ActionDouble classes in two different namespaces and folders:

 namespace Concept002 { class ActionDouble : public Action { Q_OBJECT public: ActionDouble(QObject *parent = 0); ... }; } 

and

 namespace Concept003 { class ActionDouble : public Action { Q_OBJECT public: explicit ActionDouble(QObject *parent = 0); ... signals: public slots: }; } 

We get warnings and errors:

warning: overriding recipe for target 'moc_ActionDouble.cpp'

warning: ignoring old recipe for target 'moc_ActionDouble.cpp'

and as a consequence:

error: undefined reference to `vtable for Concept002 :: ActionDouble '


Actually, this is the question, can anyone know the qmake configuration flag (or another way to solve the above problem is to have several classes in different folders and different namespaces with the same name and inherited from QObject ), which allows generating moc_ files in different folders in accordance with the structure of the project. Or, for example, it can be possible to form mocks as moc_Namespace_ClassName ?

  • In general, it is not necessary that the moc file has the same name as the corresponding cpp. You can assign them any random names. The main thing is to get the same names in the Makefile. But how to do it - the devil knows. - maestro

1 answer 1

Applications I share on a static (it is also assigned a namespace). There are no duplicate names in one lib. And I use subprojects and with hands I specify the default build directory. I declare ./build/[TARGET_ARCH] I add TARGET_ARCH via mkspec or in IDE Projects -> build -> qmake -> Extras. options.

 isEmpty(TARGET_ARCH){ TARGET_ARCH=x86 } BASE_PATH=$$PWD/$$TARGET_ARCH OBJECTSDIR = $$BASE_PATH/obj/$${MODULE_NAME}/$${BUILD_TYPE} DESTDIR = $$BASE_PATH/lib 

Project structure

 Module1 Module (namespace Module1) ClassA.cpp (Module1::ClassA) Test ClassA.cpp (тут unit test Fixture|Mocks) Module2 Module (namespace Module2) ClassA.cpp (Module2::ClassA) Test ClassA.cpp (тут unit test Fixture|Mocks) 

So zabolol duplicate object names.