简体   繁体   English

如何在c / c ++中使用某些特定的dll?

[英]How do I use some specific dll in c/c++?

Like the msvcr70/msvcr80/msvcr90.dll , what's the code like to instruct the linker to link to one of them dynamically? msvcr70/msvcr80/msvcr90.dll一样,指示链接程序动态链接到其中之一的代码是什么?

Or has that anything to do with c/c++ ,but cmake ? 还是与c/c++ ,但是cmake

The specific examples you give happen to be DLLs that are usually linked through manifests and the side-by-side, at least when building applications (with the correct project settings) from Visual Studio. 您提供的特定示例恰好是DLL,这些DLL通常通过清单和并排链接,至少在从Visual Studio构建应用程序(具有正确的项目设置)时。 Why are you trying to instruct the compiler to link them by code? 您为什么要指示编译器通过代码链接它们?

The most often-used way to link to a particular DLL is when you have the lib for the DLL available, and then to use the pragma 链接到特定DLL的最常用方法是拥有DLL的可用库,然后使用编译指示

 #pragma comment(lib, "<library name>")

链接时指定一个.lib文件,并且匹配的.dll将在运行时使用,因此(例如)如果要使用msvcr70.dll,则需要与msvcr70.lib链接。

In general, the C/C++ runtime you link against is dependent to the version of VisualStudio you are using. 通常,您链接的C / C ++运行时取决于您使用的VisualStudio版本。 (msvcr80.dll -> VS2005, msvcr90.dll -> VS2008 etc.) (msvcr80.dll-> VS2005,msvcr90.dll-> VS2008等)

Some deeper insight on how this works and some tricks to work araoud this you can read up in this blog post . 您可以在此博客文章中找到有关此方法工作原理的更深入的了解和一些技巧。

eh, surely you want to first understand DLLs/linking... http://www.infernodevelopment.com/how-create-dll-c-using-run-time-dynamic-linking 嗯,您当然想首先了解DLL /链接... http://www.infernodevelopment.com/how-create-dll-c-using-run-time-dynamic-linking

the question as written is not answerable 书面问题无法回答

Note: not sure what you mean with Cmake, but you can easily specify link libraries in your CMakeLists.txt file... the exception being the DLLs you note, because they are platform-dependent. 注意:不确定Cmake的含义,但是可以轻松地在CMakeLists.txt文件中指定链接库...例外情况是您注意到的DLL,因为它们与平台有关。 You'd need something in the CMake script to check versions of MSVC. 您需要CMake脚本中的某些内容来检查MSVC的版本。

Why would you want to link to an older run-time though, Vista onward come with the VC9 run-time, and if someone is using XP you can just give them the 'redistributable package' for VS2008/2010... 但是,为什么要链接到较旧的运行时,Vista以及VC9运行时又开始了,如果有人使用XP,则可以给他们提供VS2008 / 2010的“可分发包” ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM