将 HDF5 库链接到 Visual C++ DLL 项目:无法解析的外部符号 __imp__*
我正在使用 MS Visual C++ 2010 Express 构建一个插件,我想包含 HDF5 库的功能。我尝试过使用 CMake 从源代码构建 HDF5,并安装预编译库 (HDF5 -1.8.7_CMake_x86_shared.zip
(适用于 VC 2008)。对于任一构建目录/方法,我修改了我的项目属性:
- C/C++ >一般>其他包含目录:为 HDF5 Linker 添加
include
- >一般>其他库目录:为 HDF5 添加
lib
这是我的 DLL 模块的片段:
#include "cpp/H5Cpp.h"
static IResult OnBeginDocument (IDocument pDoc)
{
H5Fcreate("C:\\out.h5", H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
return True;
}
请注意,VC++ 正确解析 .h
文件,例如,直观地显示弹出窗口当我将鼠标悬停在该代码片段上时,H5Fcreate
的文档。我的问题是我无法构建尝试使用 H5Fcreate
的模块。以下是我的构建尝试的控制台输出:
1>MyProject.obj : error LNK2019: unresolved external symbol __imp__H5Fcreate referenced in function "int __cdecl OnBeginDocument(struct IModuleStruct *)" (?OnBeginDocument@@YAHPAUIModuleStruct@@@Z)
1>MyProject.obj : error LNK2019: unresolved external symbol __imp__H5check_version referenced in function "int __cdecl OnBeginDocument(struct IModuleStruct *)" (?OnBeginDocument@@YAHPAUIModuleStruct@@@Z)
1>C:\MyProject\Release\MyProject.dll : fatal error LNK1120: 2 unresolved externals
尝试链接 HDF5 的两种方法(预编译与自编译,如上所述)都会产生完全相同的错误,因此我不确定哪里出错了。
非常感谢@HasanKhan 和@StevieG,这些对于像我这样的n00bs 来说是很有帮助的提示。为了清楚地跟进,我确实需要在 Linker > 中添加 lib 文件路径输入>其他依赖项:
hdf5dll.lib
hdf5_cppdll.lib
如果我需要其他 HDF5 功能,我可能需要添加其他 lib 文件。另外,事实证明,我需要将 HDF5 DLL(从 bin
)复制到我的系统目录(例如,C:\WINDOWS\System32\
),以便插件能够运行时正确运行。现在一切都好,谢谢!
I'm building a plug-in with MS Visual C++ 2010 Express, and I would like to include capabilities from the HDF5 library. I have tried both building HDF5 from source with CMake, and installing the precompiled library (HDF5-1.8.7_CMake_x86_shared.zip
for VC 2008). For either build directory/method, I've modified my project property:
- C/C++ > General > Additional Include Directories: add the
include
for HDF5 - Linker > General > Additional Library Directories: add the
lib
for HDF5
Here is a snippet of my DLL module:
#include "cpp/H5Cpp.h"
static IResult OnBeginDocument (IDocument pDoc)
{
H5Fcreate("C:\\out.h5", H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
return True;
}
Note that VC++ correctly parses the .h
files to, e.g., visually show pop-up documentation for H5Fcreate
when I hover my mouse over that snippet. My problem is that I cannot build the module that tries to use H5Fcreate
. Here is the console output from my build attempts:
1>MyProject.obj : error LNK2019: unresolved external symbol __imp__H5Fcreate referenced in function "int __cdecl OnBeginDocument(struct IModuleStruct *)" (?OnBeginDocument@@YAHPAUIModuleStruct@@@Z)
1>MyProject.obj : error LNK2019: unresolved external symbol __imp__H5check_version referenced in function "int __cdecl OnBeginDocument(struct IModuleStruct *)" (?OnBeginDocument@@YAHPAUIModuleStruct@@@Z)
1>C:\MyProject\Release\MyProject.dll : fatal error LNK1120: 2 unresolved externals
Both methods of attempting to link in HDF5 (precompiled vs self-compiled, as described above) produce these exact same errors, so I'm not sure where I'm going wrong.
Many thanks to @HasanKhan and @StevieG, these were helpful tips for n00bs like me. Just to follow up clearly, I did indeed need to add lib filepaths in Linker > Input > Additional Dependencies:
hdf5dll.lib
hdf5_cppdll.lib
I may need to add other lib files if I require other HDF5 features. Also, it turned out that I needed to copy the HDF5 DLLs (from bin
) into my system directory (e.g., C:\WINDOWS\System32\
) for the plugin to operate correctly at runtime. All good now, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
链接器>一般>其他库目录:您应该添加
此处包含 .lib 文件的目录路径
Linker >一般>输入:您应该在此处添加.lib 文件的名称
Linker > General > Additional Library Directories: you should add the
path to the directory containing the .lib file here
Linker > General > Input: you should add the name of the .lib file here
检查这个东西:
我认为这就足够了。
Check this things:
I think it's enough.