Visual Studio:如何为链接器指定不同的运行时库? (/MTd、MDd 等)
我正在链接到 VS2008 中的一些库。如果我对链接器的了解是正确的,MTd 用于静态链接,MDd 用于动态链接(到 DLL)。我的目标是静态链接一些库并动态链接其他库。项目选项似乎对链接器输入中的所有库只有一种设置。我该怎么做?
I'm linking to a few libraries in VS2008. If my knowledge of the linker is correct, MTd is for static linking and MDd is for dynamic linking (to a DLL.) My goal is to statically link some libraries and dynamic link others. The project options seems to only have one setting for all libraries in the linker input. How would I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设置后,您的项目将获得一个合理的 C 运行时库默认值,具体取决于您如何回答“新建项目向导”提示。您可以按如下方式检查和更改它(如果需要):
可以根据需要链接其他库,只需在“链接器”、“输入”、“附加依赖项”下指定要链接的库即可。
即使您链接到 DLL,它仍然会有一个 .LIB 文件(DLL 的正确形式)来解析外部引用,除非您手动加载 DLL 并发现所需的函数入口点。
您确实需要确保链接的 LIB 文件使用与应用程序相同的 CRT,否则可能会出现意外错误。
Your project will be given a sensible C Runtime Library default after you set it up, depending on how you answer the New Project Wizard prompts. You can inspect and alter this (if needed) as follows:
Other libraries can be linked however you want, you just specify the library to link to under Linker, Input, Additional Dependencies.
Even if you are linking to a DLL, it will still have a .LIB file (of the correct form for a DLL) to resolve external references, unless you are manually loading the DLL and discovering required function entry points.
You do need to make sure that the LIB files you link to use the same CRT as your app does, or things can go unexpectedly wrong.
不,你把它搞混了。 /MD 与 /MT 选项仅与您链接的 CRT 版本相关。有两个静态版本 (/MT),仅当您的项目中不使用任何 DLL 时才应使用。还有 DLL 版本,进程中的每个二进制文件都可以共享该版本,这样您就不会遇到堆分配的痛苦。当内存被一个模块分配并被另一个模块释放时,你会陷入一种痛苦。
选择自己的库完全取决于您。混合和匹配很好,链接器只是获得另一种 .lib。导入库而不是静态库。使用 DLL 时请记住使用 /MD。
No, you're mixing it up. The /MD vs /MT options is only relevant to which CRT version you link. There are two, the static version (/MT) which you should use only if you don't use any DLLs in your project. And the DLL version, a version that every binary in your process can share so that you won't have heap allocation misery. The kind of misery you get into when memory is allocated by one module and freed by another.
Choosing your own libraries is entirely up to you. Mixing and matching is fine, the linker just gets another kind of .lib. An import library instead of a static library. Just keep in mind to use /MD when you use DLLs.
您描述的链接器选项仅适用于 CRT。静态版本将限制模块之间共享内存的方式。
您使用的所有其他库都将根据您向链接器提供(或不提供)的 .lib 文件进行链接。
有 3 种使用 MS 库的方法
The linker options your describing are for the CRT only. The static version will limit how you share memory between modules.
All other libraries you use will have be linked in based on the .lib files you provide(or not) to the linker.
There are 3 ways to use a MS library