问题描述
我遇到了一段使用#pragma comment(lib, libraryname)的代码。
I came across a piece of code which uses #pragma comment(lib, "libraryname").
为什么使用这种用法而不是仅仅链接库从属性菜单?在什么情况下需要这种用法?我在Windows中使用C ++ 。
Why this type of usage as opposed to just linking the library from the properties menu? In what situations is this usage called for? I am in windows using C++ Visual Studio 2010.
很高兴看到一个需要这种用法的示例。
It would be nice to see an example which calls for this type of usage.
推荐答案
库编写器可以在公共头文件(.h)中放置 #pragma comment(lib,...)
命令。在这种情况下,客户端无需将此库添加到链接器依赖项列表。通过在程序中包含h文件,客户端将自动链接到所需的库。
The library writer can place a #pragma comment(lib, ...)
command in the public header (.h) file. In this case, the client doesn't need to add this library to the linker dependencies list. By including an h-file in the program, the client is automatically linked to the required library.
这篇关于C ++ Visual Studio:使用注释注释链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!