自动添加“附加包含目录"静态库的用户 [英] automatic add "Additional include directory" to user of a static library

查看:32
本文介绍了自动添加“附加包含目录"静态库的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序项目 (MyGame),它在同一个解决方案中使用/调用我的静态库 (MyLib):-

I have an application project (MyGame) that uses/calls my static library (MyLib) in the same solution:-

MySol\
- MyLib (static library)   use "external"
- MyGame (win32 app)       use "MyLib"  

从上图中,MyLib 需要一个不是我自己编码的外部库.
外部头文件位于 D:\external\.

From the above diagram, MyLib need an external library that is not coded by me.
The external header resides in D:\external\.

这是使一切正常的正确设置:-

This is a correct setting that make everything works :-

  1. MyLib附加包含目录 = D:\external\;

MyGame附加包含目录 = D:\MySol\MyLib\;D:\external\;

请注意,我必须将 Additional Include Directories = D:\external\; 添加到两个项目中.

Notice that I have to add Additional Include Directories = D:\external\; into both projects.

当我有很多项目时,在现实生活中会一团糟.
(乏味、难以维护、容易出错和脏)

It is a mess in real-life when I have a lot of projects.
(tedious, hard-to-maintain, error-prone and dirty)

属性表可以稍微缓解问题,但不能彻底治愈.

Property sheet can alleviate the problem a little, but not totally cure.

我希望我可以简短地包括:-

I wish I can include shortly as :-

  1. MyGame附加包含目录 = D:\MySol\MyLib\; <-- 没有外部"是的!
  1. MyGame's Additional Include Directories = D:\MySol\MyLib\; <-- no "external" yea!

这无法编译,因为项目MyGame 无法访问\external 中的标头.(废话,为什么不自动化?)

This can't be compiled because the project MyGame can't access the header in \external. (non-sense, why is it not automated?)

MyLib 添加到 MyGame参考(解决方案资源管理器)没有帮助.

Adding MyLib to MyGame's Reference (Solution Explorer) doesn't help.

如何让静态库项目 (MyGame) 的用户自动吸收 其他包含目录(\external) 的静态库项目 (MyLib)?

How to make a user of a static-library project (MyGame) automatically absorb Additional Include Directories (\external) of the static-library project (MyLib)?

推荐答案

正如您现在所发现的,属性表通常是实现此类部分自动化的简单方法(另一种方法是例如像 VcPkg 但据我所知,这还没有(还)正确建立,而且不像创建单个文件那么容易只需单击几下即可将其添加到项目中).在这种情况下:创建一个属性表,将 d:\external 添加到 AdditionalIncludeDirectories 并在所有需要它的项目中导入该表.此外,如果您不使用 pragma 进行自动链接和/或库不在所有项目都知道的公共位置,您可以将库搜索路径和库本身添加到属性表中的链接器输入中,以获得编译器和链接器高兴.

As you discovered by now, property sheets are usually the easy way to get things like this partly automated (another way is for instance package managment like VcPkg but that is not (yet) properly established as far as I know, and not as easy as creating a single file and adding it to a project with a couple of clicks). In this case: create a property sheet which adds d:\external to AdditionalIncludeDirectories and import the sheet in all projects needing it. Also if you don't use a pragma for autolinking and/or the libraries are not in a common location known by all projects you can add the library search path and library itself to the linker input in the propperty sheet to get both the compiler and linker happy.

这篇关于自动添加“附加包含目录"静态库的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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