将 HDF5 库链接到 Visual C++ DLL 项目:无法解析的外部符号 __imp__*

发布于 2024-12-04 06:54:41 字数 1724 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信仰 2024-12-11 06:54:41
  • 链接器>一般>其他库目录:您应该添加
    此处包含 .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

流年里的时光 2024-12-11 06:54:41

检查这个东西:

  1. 链接器>输入>附加依赖项包含hdf5.lib
  2. 链接器>一般>其他库目录包含 HDF5 安装的 lib 目录的路径
  3. C/C++ >一般>其他包含目录包含 HDF5 安装的包含目录的路径
  4. 构建配置与已安装的 HDF5 版本(32>64 位
  5. 您添加到 HDF5 安装的 PATH 变量 bin 目录

我认为这就足够了。

Check this things:

  1. Linker > Input > Additional Dependencies contains hdf5.lib
  2. Linker > General > Additional Libraries Directories contains path to lib directory of your HDF5 installation
  3. C/C++ > General > Additional Include Directories contains path to include directory of your HDF5 installation
  4. You build configuration match to installed HDF5 version (32 or 64 bit)
  5. You add to PATH variable bin directory of your HDF5 installation

I think it's enough.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文