Visual C ++中的DLL引用 [英] DLL References in Visual C++

查看:180
本文介绍了Visual C ++中的DLL引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C ++经验,但没有MSVC。



我想要做的是将.dll从开放源码项目纳入我的项目。代码可用,我已经构建了它。我有.dll以及.lib,据了解,这是C ++项目所必需的。



现在不幸的是没有简单的添加参考,删除我的.dll进入包含目录,并将其添加到我的解决方案。我已经编辑了项目属性页面,C / C ++ Additional Include Directories选项以及添加.lib作为附加的链接器依赖关系。我已经在我的解决方案树中为dll和lib创建了一个include目录。



我的问题是当我尝试从文档中包含头文件时,VS输出吐出错误信息。现在我意识到我正在使用dll / lib组合,并且我的解决方案中不存在.h文件,所以如何添加正确的包括?我正在使用QT工具包,这是正在工作,但我如何从开放源代码库中添加其他标题/ DLL不包括我。



有人可以指向正确的方向。

解决方案

您需要做几件事才能使用图书馆:


  1. 确保您同时拥有* .lib和* .dll从您想要使用的库。如果您没有* .lib,请跳过#2


  2. 在项目中引用* .lib。右键单击解决方案资源管理器中的项目名称,然后选择配置属性 - >链接器 - >输入,并将其名称放在附加依赖关系属性中。


  3. 你必须确保VS可以找到你刚刚添加的lib,所以你必须去工具菜单并选择选项...然后在项目和解决方案下选择VC ++目录。在这里,您可以通过在显示目录为:下拉框中选择库文件来设置包含新库的目录。只需将路径添加到目录列表中的lib文件。如果你没有lib,你可以省略这个,但是当你在这里你还需要在'Include Files'下设置包含头文件的目录。这样做与您添加的lib一样。


做完之后,你应该很好,可以使用你的图书馆。如果你没有一个lib文件,你仍然可以自己导入dll。在应用程序启动期间,您可以通过调用LoadLibrary来显式加载dll(请参阅: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx 了解更多信息)



干杯!



编辑



请记住使用#include< Foo.h>而不是#includefoo.h。前者搜索包含路径。后者使用本地项目文件。


I have had C++ experience but not MSVC.

What I am trying to do is incorporate a .dll from an open source project into my project. The code is available and I have built it. I have the .dll as well as the .lib which as I understand it is required for C++ projects.

Now unfortunately there is no simple "Add Reference", drop my .dll into an include directory and add that to my solution. I have edited the project property pages, the C/C++ Additional Include Directories option as well as adding the .lib as an additional linker dependency. I have created an include directory for the dll and lib inside my solution tree.

My problem is when I try to include the header files from the documentation, VS output spits out error messages. Now I realize that I am using the dll/lib combo and that the .h files are not present in my solution so how do I add the proper includes? I am using QT toolkit also which is working but how I add the other header / dll from the open source library eludes me.

Can someone please point me in the right direction.

解决方案

You need to do a couple of things to use the library:

  1. Make sure that you have both the *.lib and the *.dll from the library you want to use. If you don't have the *.lib, skip #2

  2. Put a reference to the *.lib in the project. Right click the project name in the Solution Explorer and then select Configuration Properties->Linker->Input and put the name of the lib in the Additional Dependencies property.

  3. You have to make sure that VS can find the lib you just added so you have to go to the Tools menu and select Options... Then under Projects and Solutions select VC++ Directories. From within here you can set the directory that contains your new lib by selecting the 'Library Files' in the 'Show Directories For:' drop down box. Just add the path to your lib file in the list of directories. If you dont have a lib you can omit this, but while your here you will also need to set the directory which contains your header files as well under the 'Include Files'. Do it the same way you added the lib.

After doing this you should be good to go and can use your library. If you dont have a lib file you can still use the dll by importing it yourself. During your applications startup you can explicitly load the dll by calling LoadLibrary (see: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx for more info)

Cheers!

EDIT

Remember to use #include < Foo.h > as opposed to #include "foo.h". The former searches the include path. The latter uses the local project files.

这篇关于Visual C ++中的DLL引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆