Issue
In a typical C++ application (no Qt), I may have the following:
app/include/namespace1/Foo.h
app/src/namespace1/Foo.cpp
app/include/namespace2/Foo.h
app/src/namespace2/Foo.cpp
Where "app" is the root folder for the project. The classes in those files are:
//In app/include/namespace1/Foo.h
namespace namespace1 {
class Foo;
}
//In app/include/namespace2/Foo.h
namespace namespace2 {
class Foo;
}
In a build system like the one eclipse has, the object files for each .cpp files will be built into diffrent subdirectories.
In Qt, I create a .pri file in each of my folders which contains include
, SOURCES
, and HEADERS
statements. However, when Qt builds the program, it places all of the object files in the same directory. So, [build output]/Foo.o gets generated twice and thus overwritten causing the linker to fail.
I looked into making each nested folder into its own SUBDIRS
project with its own .pro file, but this doesn’t work correctly since each folder is not an independent project, just an independent namespace.
What is the correct way to setup a project like this?
Solution
Here is one answer: https://riptutorial.com/qt/example/15975/preserving-source-directory-structure-in-a-build–undocumented—object-parallel-to-source–option–
This causes Qt to generate a directory structure in the build directory that "mirrors" the source directories.
Answered By – Patrick Wright
Answer Checked By – Pedro (BugsFixing Volunteer)