QtCreator:避免在Qt子目录项目中重新定义LIBS [英] QtCreator: Avoid redefining LIBS in Qt subdirs project

查看:393
本文介绍了QtCreator:避免在Qt子目录项目中重新定义LIBS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Qt subdirs project,具有以下结构:

I have a Qt subdirs project with the following structure:

ExternalQtProject 
QtSubdirProjects
  - GUI
  - WebService

WebService包含来自外部Qt项目(WebService中的.pro文件)的LIBS

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

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

GUI使用Web服务(GUI中的.pro文件):

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

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

因此,基本上GUI使用的是WebService中的一个头文件,而该文件又使用了ExternalQtProject中的多个头文件.

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

问题:在我将WebService中的LIBS条目也包括在GUI中之前,我遇到了链接器问题,因此GUI最终会包含ExternalQtProject中的所有LIBS:

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>

由于存在明确的依赖性(GUI-> WebService-> ExternalQtProject),因此是否有办法避免对GUI子项目重新定义LIBS ?

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

-编辑1-

如何使用QMake的subdirs模板?帮助我更好地构建我的结构项目,但尚未避免重复LIBS

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

推荐答案

Qmake .pro文件可以使用变量并包含其他文件.

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

您可以例如必要时使用SOMELIST = foo.obj bar.obj和LIBS + = $$ SOMELIST.

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

SUBDIRS模板用于列出不同的.pro文件,每个文件通常负责构建一个二进制文件或一个库.

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

这篇关于QtCreator:避免在Qt子目录项目中重新定义LIBS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆