【发布时间】:2014-06-18 10:43:10
【问题描述】:
我有几个关于如何做才能拥有满足我需求的最佳组织项目的问题。
上下文
我正在研究 QT5,我有一个这样的项目:
MyProject /
MyProject.pro
src /
src.pro // target = app (include Controller.pro and View.pro)
Controller /
Controller.pro // no target, just add some sources
Component1 /
Component2 /
...
View /
View.pro // no target, just add some sources
Component10 /
Component11 /
...
main.cpp
test /
Controller /
Component1 /
Component1.pro // target = app
main.cpp
...
View /
Component10 /
Component10.pro // target = app
main.cpp
...
编译
目前,一切正常,除了我的项目越大,编译时间就越长。 (大约 2 分钟)。
我检查了发生的情况,问题是,在每个测试子项目文件中,我都包含 Controller.pro 以便拥有我的所有源代码。
这样做,我编译了 N 次我的源代码,这就是它太长的原因。
(在生成的文件/文件夹中,我有类似的东西)
build-MyProject /
src /
main.o
component1.o
component2.o
component10.o
...
test /
Controller /
Component1 /
main.o
component1.o
...
View /
Component10 /
main.o
component10.o
...
Component1 和 Component10 已经编译了两次。
我想要什么
显然,我想为每个文件生成一次对象。理想情况下,类似于:
MyProject /
obj /
src /
Controller /
component1.o
component2.o
View /
component10.o
main.o
test /
Controller /
Component1 /
main.o
View /
Component10 /
main.o
我不知道该怎么做
1- 主要问题是,我不知道如何告诉 QMake 我想将 ob/src/Controller/Component1.o 与 obj/test/Controller/main.o 链接起来
2- 根据你的经验,这样的组织,是好事还是太复杂,太分离,...?
3- 使用 qmake 工具,我看到您可以定义 target = app 或 target = lib 来生成可执行文件或库。是否有关键字只生成对象而不执行链接? (我可以在关键字 SOURCES 中删除 main.cpp 但 make 尝试链接所有对象,并且我对 main 的引用未定义...)
提前致谢。
【问题讨论】:
标签: qt qt-creator qmake project-organization project-structure