windows 库导入:#pragma comment VS Visual Studio 项目输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6287338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Library importing: #pragma comment VS Visual studio project input
提问by Benjamin
- using #pragma comment(lib, "../../xxx.lib")
- using Visual studio project option
- 使用 #pragma 注释(lib,“../../xxx.lib”)
- 使用 Visual Studio 项目选项
What is the advantage and disadvantage between two method?
I'm finding way which is better convenient to manage for many projects.
两种方法的优缺点是什么?
我正在寻找更方便管理许多项目的方法。
And what method does Microsoft recommend?
微软推荐什么方法?
采纳答案by Hans Passant
The advantage of #pragma comment is that the user of your library cannot forget to add the setting. Or add the wrong one, it is not uncommon to get lost at the difference between the debug and release build and the /MD vs /MT build. One disadvantage is that troubleshooting linker problems can be difficult in some cases.
#pragma comment 的优点是您图书馆的用户不会忘记添加设置。或者添加错误的,在调试和发布版本与 /MD 与 /MT 版本之间的差异中迷失的情况并不少见。一个缺点是在某些情况下对链接器问题进行故障排除可能很困难。
There's a third way that's hard to beat for convenience in a solution. Right-click the project that requires the library and click Project Dependencies. Tick the library project. This ensures that the library project is always built before the project andthe .lib is automatically added.
为了解决方案中的便利,还有第三种方法很难被击败。右键单击需要库的项目,然后单击项目依赖项。勾选库项目。这可确保库项目始终在项目之前构建,并且.lib 会自动添加。