在 Visual Studio 2012 中从另一个项目中引用 DLL [英] Referencing DLL from one project in another in visual studio 2012

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

问题描述

我是 Visual Studio 的新手,正在尝试从同一解决方案中的另一个项目引用一个项目的 dll.我已经添加了引用、指定了项目依赖项并设法在代码中引用了头文件,但是当我构建解决方案时,我收到类似于以下内容的错误:

I am a newbie to Visual Studio and am trying to reference a dll of one project from another in the same solution. I've added references, specified project dependencies and managed to reference header files within the code but when I build the solution I get errors similar to the following:

unresolved external symbol "int __cdecl increment(int)" 

推荐答案

AFAIK,本机 DLL 项目的依赖项在 VisualStudio 中不是自动的.

AFAIK, dependencies to native DLL projects are not automatic in VisualStudio.

但是您可以手动添加依赖项.当您编译 DLL 时,它实际上会构建一个 .dll 文件和一个 .lib 文件.所以在使用该库的项目的属性中,进入Linker->Input->Additional Dependencies并添加.lib文件的名称.

But you can add the dependency manually. When you compile the DLL it will actually build a .dll file and a .lib file. So in the properties of the project that uses the library, go to Linker->Input->Additional Dependencies and add the name of the .lib file.

请记住,要使 increment() 函数正常工作,您必须在 DLL 中编译它时将其声明为 __declspec(dllexport).在客户端程序中使用时,将其编译为 __declspec(dllimport) 通常是个好主意.习惯上使用一些宏来共享同一个 .h 文件.

Remember that, for the increment() function to work properly, you have to declare it as __declspec(dllexport) when compiling it in the DLL. And it is usually a good idea to compile it as __declspec(dllimport) when used in the client program. It is customary to use some macros to share the same .h file.

这篇关于在 Visual Studio 2012 中从另一个项目中引用 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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