如何“添加参考"?在C ++中 [英] How to "add reference" in C++
问题描述
我是C ++的新手,有一些我完全不了解的东西.在C#中,如果要使用外部库(例如log4net),则只需添加对log4net DLL的引用,它的成员对我(以及在IntelliSense中)自动可用.如何在非托管C ++中做到这一点?
I'm new to C++ and there's something I just completely don't get. In C#, if I want to use an external library, log4net for example, I just add a reference to the log4net DLL and its members are automatically available to me (and in IntelliSense). How do I do that in non-managed C++?
推荐答案
通常,该库附带1)头文件(.h)和2)除.dll之外的.lib文件.
Often, the library comes with 1) a header file (.h) and 2) a .lib file in addition to the .dll.
标头文件已包含在您的代码中,使您可以访问库中的类型和函数声明.
The header file is #include'ed in your code, to give you access to the type and function declarations in the library.
.lib已链接到您的应用程序(项目属性->链接器->输入,其他依赖项).
The .lib is linked into your application (project properties -> linker -> input, additional dependencies).
.lib文件通常包含一些简单的存根,这些存根会自动加载dll并将函数调用转发给它.
The .lib file usually contains simple stubs that automatically load the dll and forward function calls to it.
如果没有.lib文件,则必须使用LoadLibrary函数动态加载DLL.
If you don't have a .lib file, you'll instead have to use the LoadLibrary function to dynamically load the DLL.
这篇关于如何“添加参考"?在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!