在不获取LNK4006的情况下在Visual C ++中链接具有依赖项的库 [英] Link libraries with dependencies in Visual C++ without getting LNK4006

查看:108
本文介绍了在不获取LNK4006的情况下在Visual C ++中链接具有依赖项的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组静态编译的库,这些库之间有相当深入的依赖关系.例如,可执行文件X使用库A和B,A使用库C,而B使用库C和D:

I have a set of statically-compiled libraries, with fairly deep-running dependencies between the libraries. For example, the executable X uses libraries A and B, A uses library C, and B uses libraries C and D:

X -> A
     A -> C
X -> B
     B -> C
     B -> D

当我将X链接到A和B时,如果C和D也未添加到库列表中,我不想出错-A和B在内部使用这些库的事实是X的实现细节应该不需要知道的.同样,当新的依赖项添加到依赖项树中的任何位置时,必须重新配置使用A或B的任何程序的项目文件.对于深度依赖树,所需的库列表可能会变得很长且难以维护.

When I link X with A and B, I don't want to get errors if C and D were not also added to the list of libraries—the fact that A and B use these libraries internally is an implementation detail that X should not need to know about. Also, when new dependencies are added anywhere in the dependency tree, the project file of any program that uses A or B would have to be reconfigured. For a deep dependency tree, the list of required libraries can become really long and hard to maintain.

因此,我在A项目中使用库管理器部分的其他依赖关系"设置,并添加了C.lib.在B项目的同一部分中,我添加了C.lib和D.lib.这样的作用是,图书馆员将C.lib捆绑到A.lib中,并将C.lib和D.lib捆绑到B.lib中.

So, I am using the "Additional Dependencies" setting of the Librarian section in the A project, adding C.lib. And in the same section of B's project, I add C.lib and D.lib. The effect of this is that the librarian bundles C.lib into A.lib, and C.lib and D.lib into B.lib.

但是,当我链接X时,A.lib和B.lib都包含自己的C.lib副本.这会导致大量的

When I link X, however, both A.lib and B.lib contain their own copy of C.lib. This leads to tons of warnings along the lines of

A.lib(c.obj):警告B.lib(c.obj)中已定义的LNK4006符号"(_symbol);第二个定义被忽略.

A.lib(c.obj) : warning LNK4006 "symbol" (_symbol) already defined in B.lib(c.obj); second definition ignored.

如何在不收到警告的情况下完成此任务?有没有一种方法可以简单地禁用警告,还是有更好的方法?

How can I accomplish this without getting warnings? Is there a way to simply disable the warning, or is there a better way?

编辑:我已经看到了多个答案,这表明,由于缺乏更好的选择,我只是禁用了警告.好吧,这是问题的一部分:我什至不知道如何禁用它!

EDIT: I have seen more than one answer suggesting that, for the lack of a better alternative, I simply disable the warning. Well, this is part of the problem: I don't even know how to disable it!

推荐答案

据我所知,您不能禁用链接器警告. 但是,可以使用链接器的命令行参数(例如)忽略其中的一些. /ignore:4006

As far as I know you can't disable linker warnings. However, you can ignore some of them, using command line parameter of linker eg. /ignore:4006

将其放在链接器->命令行设置下的项目属性中(不记得确切的位置).

Put it in your project properties under linker->command line setting (don't remember exact location).

也请阅读:

链接/ignore

MSDN论坛-隐藏LNK警告

Wacek

这篇关于在不获取LNK4006的情况下在Visual C ++中链接具有依赖项的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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