QtCreator: Avoid redefining LIBS in Qt subdirs project

你离开我真会死。 提交于 2019-12-24 17:55:59

问题


I have a Qt subdirs project with the following structure:

ExternalQtProject 
QtSubdirProjects
  - GUI
  - WebService

WebService contains LIBS from the external Qt project (.pro file in WebService)

LIBS += -L<path to ExternalQtProject>
LIBS += <some ExternalQtProject .obj files>

GUI uses the web service (.pro file in GUI):

LIBS += -L<path to WebService>
LIBS += <WebService .obj files>

So basically GUI is using one header file from WebService, which in turn uses several header files from ExternalQtProject.

Problem: I get linker issues until I include the LIBS entries from WebService as well in GUI, so GUI ends up with all LIBS from the ExternalQtProject:

LIBS += -L<path to ExternalQtProject> # I want to avoid redefinition of this
LIBS += <some ExternalQtProject .obj files>  # I want to avoid redefinition of this
LIBS += -L<path to WebService>
LIBS += <WebService .obj files>

Since there is a clear dependency (GUI->WebService->ExternalQtProject), is there a way to avoid this redefinition of LIBS for the GUI sub project?

-- Edit 1 --

How to use QMake's subdirs template? helps me to better structure my project, but not yet avoiding the duplication of LIBS


回答1:


Qmake .pro files can use variables and include other files.

You can e.g. use SOMELIST=foo.obj bar.obj and LIBS += $$SOMELIST when needed.

A SUBDIRS template is used to list different .pro files, each typically responsible for building one binary or one library.



来源:https://stackoverflow.com/questions/11616647/qtcreator-avoid-redefining-libs-in-qt-subdirs-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!