在 Visual Studio 2010 C++ 中链接 DLL
我正在尝试使用 C++ 的 M4RI 包。我下载了 M4RI 的源代码并运行了打包的 VS 项目。它创建了 m4ri.dll(无 .lib 文件)。 现在我想将此 dll 文件“添加”到不同的 VS2010 C++ 项目中,以便我可以使用 M4RI 库。
我已经#include m4ri.h,但仍然出现链接错误。如何将此引用添加到 VS 项目中?
提前致谢。
I am trying to use the M4RI package for C++. I downloaded the source for M4RI and ran the packaged VS project. It created m4ri.dll (no .lib files).
Now I want to "add" this dll file to a different VS2010 C++ project so I can use the M4RI library.
I already #include m4ri.h, but still get linking errors. How do I add this reference to the VS project?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的解决方案:
我不熟悉 C 和 C++ 之间的差异,但这似乎是问题所在。为了构建 M4RI 库,我必须明确告诉它使用 C++ 进行编译(属性 -> C/C++ -> 高级 -> 编译为:“编译为 C++”)
我不确定这是否导致我的问题,或者如果它不相关。
为了能够使用该库,我必须修改“m4ri.h”以删除#ifdef __cplusplus部分。一旦这些预编译器指令被删除,我就能够轻松链接到 M4RI。
如果有人能解释为什么这解决了问题,我将不胜感激。
谢谢!
My solution:
I am not familiar with the differences between C and C++, but this seems to be the issue. To get the M4RI library to build, I had to explicitly tell it to compile with C++ (Properties->C/C++->Advanced->Compile As: "Compile as C++")
I'm not sure if this caused my problem, or if it is unrelated.
To be able to use the library, I had to modify "m4ri.h" to remove the #ifdef __cplusplus sections. As soon as those precompiler directives were removed, I was able to link to M4RI easily.
I would appreciate if someone could explain why this fixed the problem.
Thanks!
链接错误可能来自多种原因。您的链接错误与 m4ri 有关吗?对于 dll,您通常会获得一个导出库,该库应包含在您的项目中。
Linking errors can come from many things. Are your link errors related to m4ri? With dlls, you usually get a an export lib which should be included in your project.