Visual Studio C++ - 检查链接特定库的原因

jea*_*ean 3 c++ linker visual-studio-2012

vs报告错误,例如:

  1. 找不到xxx.lib
    如何查看为什么vs需要链接xxx.lib?有跟踪日志吗?我的项目没有使用boost.regex,但vs报告错误说无法找到regex.lib.所以我想找出代码的哪一部分引用正则表达式

  2. LNK错误:LIBCMT.lib:xxx已经在LIBCMTD.lib中定义了
    如何检查为什么vs也链接yyy.lib,即使这是一个调试版本?我有2个项目,它们链接到相同的库,所有库和项目本身都是/ MTd.但其中一个会报告上面的错误,我认为它不应该链接LIBCMT.lib,因为它是一个发布版本的lib,另一个项目是正常的,所以lib文件是正确构建的

VS可以显示链接跟踪吗?

Rud*_*lis 5

1) Let's start with how the linker actually knows what to link with. Basically there are 2 categories:

  • Libraries specified in the project settings in the linker options as additional inputs
  • Libraries added in code with precompiler directive #pragma comment (generally the same thing as above but people have different tastes)

Otherwise you just get information about missing symbols but not the actual library they are from. What you can do to help is under visual studio linker options set Show Progress to For Libraries Searched (or just /VERBOSE:LIB linker flag), that will actually show you what dependencies are added after each lib is loaded, this also helps with point 2) to see which library loads which run-time.

2)1)中已经提到过你可以让链接器显示库加载进度,否则如果你链接的外部库中使用动态C运行时你可以使用Dependency Walker to examine the dependencies of the library and find if the C run-time dll that is needed is debug or release by 'd' suffix in the dll name. If the library is already linked with static run-time then I guess only the linker errors will warn you. But I think that most serious libraries are correctly packed and structured so that you will be able to tell which files contain the debug version and which the release. If the library has only release version, well than that's another story. But i mean still, you can reconfigure the Debug 您的项目配置实际链接到发布运行时以满足外部库,当然这可以防止一些调试功能,调试堆等.