How to Disable Auto-link for TBB

2019-09-01 02:19发布

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?

标签: c++ linker tbb
2条回答
不美不萌又怎样
2楼-- · 2019-09-01 02:54

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.

查看更多
乱世女痞
3楼-- · 2019-09-01 02:58

If the autolinking with tbb_debug.lib is accomplished with:

#pragma comment( lib, "tbb_debug" )

then as explained on the MSDN documentation page for pragma comment:

Places a library-search record in the object file. ... The library name follows the default library-search records in the object file; the linker searches for this library just as if you had named it on the command line provided that the library is not specified with /nodefaultlib.

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.

查看更多
登录 后发表回答