如何禁用 TBB 的自动链接
当我将 VS 项目构建为“调试”时,它总是自动与 tbb_debug.lib 链接(反过来又与 tbb_debug.dll 链接)。有没有办法覆盖它并使 tbb.lib 链接甚至对于调试版本?
When I build my VS project as Debug, it always auto-linked with tbb_debug.lib (which in turn linked with tbb_debug.dll). Is there a way to override this and make tbb.lib linked even for a Debug build?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您确定它是“自动链接”吗?
如果是这样,则可以使用#pragma comment(lib, tbb_debug.lib)来完成。找到该代码的位置,如果是您的,则修改它,或者以某种方式禁用它(通过不包含该代码所在的文件,或者通过 #defining 禁用这段代码的内容;任何理智的库编写者都应该提供这样的机制并且也应该清楚地记录下来)。
如果没有这样的编译指示,则会链接该库,因为它出现在项目设置中。右键项目->属性->链接器->输入并调整。
编辑感谢Alexey的评论,看来您可以禁用TBB的自动链接,如
First, are you sure it is 'auto-linked'?
If so, this is done using
#pragma comment( lib, tbb_debug.lib )
. Find where this code is, modify it if it's yours, or else disbale it somehow (either by do not including the file where that code is, or by #defining something that disables this piece code; any sane library writer should provide such a mechanism and it should be documented clearly as well).If there is no such pragma, the library is linked because it appears in the project settings. Right-click project->Properties->Linker->Input and adjust.
Edit thanks to Alexey's comment it seems that you can probably disable TBB's autolinking, as seen in this header file. Defining
__TBB_NO_IMPLICIT_LINKAGE
should do the trick.如果与
tbb_debug.lib
的自动链接是通过以下方式完成的:则如
pragma comment
的 MSDN 文档页面:您可以通过传递链接器选项
/NODEFAULTLIB:tbb_debug.lib
,通过#pragma comment( lib, "tbb_debug" )
禁用自动链接。但是,您问这个问题是因为您收到“多重定义符号”错误 (LNK1169) 还是 LNK4098?如果是这样,您可能已将 tbb.lib 列为调试和发布配置文件的链接器的输入。您应该删除调试配置文件的此条目,因为会自动链接到正确的库。
If the autolinking with
tbb_debug.lib
is accomplished with:then as explained on the MSDN documentation page for
pragma comment
:You could disable the autolinking via
#pragma comment( lib, "tbb_debug" )
by passing the linker option/NODEFAULTLIB:tbb_debug.lib
.However, are you asking because you are receiving a "multiply defined symbols" error (LNK1169) or perhaps LNK4098? If so, it may be that you have
tbb.lib
listed as input to linker for both Debug and Release profiles. You should remove this entry for the Debug profile as the correct library is being automatically linked in.