为什么在执行 HDF5 示例代码期间出现 libhdf5_hl not loaded 错误?
Why I am getting libhdf5_hl not loaded error during executing the HDF5 example code?
我正在尝试执行 c 程序来执行 HDF5 基本代码。那是在下面。
/*
* This example illustrates how to create a dataset that is a 4 x 6
* array. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create the data space for the dataset. */
dims[0] = 4;
dims[1] = 6;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the dataset. */
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
/* Terminate access to the data space. */
status = H5Sclose(dataspace_id);
/* Close the file. */
status = H5Fclose(file_id);
}
我没有收到任何编译时错误,但是 运行 时间错误说它无法加载某些库。错误粘贴在下面 -
19:36:27 macOS_ ⚡ h5cc -show myprog.c
clang -arch x86_64 myprog.c -L/Users/Ajay/anaconda/lib -lhdf5_hl -lhdf5 -arch x86_64 -lpthread -lz -ldl -lm
19:36:33 macOS_ ⚡ ./a.out
dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib
Referenced from: /Users/Ajay/opensource/HDF5-Examples/./a.out
Reason: image not found
Abort trap: 6
19:36:35 macOS_ ⚡
有关配置的更多信息 -
09:11:59 macOS_ ⚡ h5cc -showconfig
SUMMARY OF THE HDF5 CONFIGURATION
=================================
General Information:
-------------------
HDF5 Version: 1.8.17
Configured on: Tue Aug 2 08:44:51 BST 2016
Configured by: ray@rays-Mac.local
Configure mode: production
Host system: i386-apple-darwin11.4.2
Uname information: Darwin rays-Mac.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
Byte sex: little-endian
Libraries: shared
Installation point: /Users/Ajay/anaconda
Compiling Options:
------------------
Compilation Mode: production
C Compiler: /usr/bin/clang ( Apple LLVM version 4.2 )
CFLAGS: -arch x86_64
H5_CFLAGS: -O3
AM_CFLAGS:
CPPFLAGS:
H5_CPPFLAGS: -DNDEBUG -UH5_DEBUG_API
AM_CPPFLAGS:
Shared C Library: yes
Static C Library: no
Statically Linked Executables: no
LDFLAGS: -arch x86_64
H5_LDFLAGS:
AM_LDFLAGS:
Extra libraries: -lpthread -lz -ldl -lm
Archiver: ar
Ranlib: ranlib
Debugged Packages:
API Tracing: no
Languages:
----------
Fortran: no
C++: yes
C++ Compiler: /usr/bin/clang++ ( Apple LLVM version 4.2 )
C++ Flags: -arch x86_64
H5 C++ Flags: -O3
AM C++ Flags:
Shared C++ Library: yes
Static C++ Library: no
Features:
---------
Parallel HDF5: no
High Level library: yes
Threadsafety: yes
Default API Mapping: v18
With Deprecated Public Symbols: yes
I/O filters (external): deflate(zlib)
MPE: no
Direct VFD: no
dmalloc: no
Clear file buffers before write: yes
Using memory checker: no
Function Stack Tracing: no
Strict File Format Checks: no
Optimization Instrumentation: no
库位置
09:11:56 macOS_ ⚡ ls /Users/Ajay/anaconda/lib | grep hdf5
-rwxr-xr-x 2 Ajay staff 17232 Aug 2 2016 libhdf5_hl_cpp.11.dylib
-rwxr-xr-x 2 Ajay staff 123256 Aug 2 2016 libhdf5_hl.10.dylib
-rwxr-xr-x 2 Ajay staff 445776 Aug 2 2016 libhdf5_cpp.12.dylib
-rwxr-xr-x 2 Ajay staff 2622428 Aug 2 2016 libhdf5.10.dylib
lrwxr-xr-x 1 Ajay staff 20 Mar 25 09:11 libhdf5_cpp.dylib -> libhdf5_cpp.12.dylib
lrwxr-xr-x 1 Ajay staff 16 Mar 25 09:11 libhdf5.dylib -> libhdf5.10.dylib
-rwxr-xr-x 1 Ajay staff 1087 Mar 25 09:11 libhdf5_hl_cpp.la
lrwxr-xr-x 1 Ajay staff 23 Mar 25 09:11 libhdf5_hl_cpp.dylib -> libhdf5_hl_cpp.11.dylib
-rwxr-xr-x 1 Ajay staff 988 Mar 25 09:11 libhdf5_hl.la
lrwxr-xr-x 1 Ajay staff 19 Mar 25 09:11 libhdf5_hl.dylib -> libhdf5_hl.10.dylib
-rwxr-xr-x 1 Ajay staff 993 Mar 25 09:11 libhdf5_cpp.la
-rw-r--r-- 1 Ajay staff 2243 Mar 25 09:11 libhdf5.settings
-rwxr-xr-x 1 Ajay staff 937 Mar 25 09:11 libhdf5.la
Based on the comment I can now run using
DYLD_LIBRARY_PATH=/Users/Ajay/anaconda/lib ./a.out
How to make it permanent ?
我不在 Mac 上,也不使用 Anaconda。无论如何,我会尝试猜测诊断您的问题:-)
- 程序生成但不会执行。可执行文件 (
libhdf5_hl.10.dylib
) 请求的库与您系统中的库不匹配。
- 您正在使用安装了 hdf5 的 Anaconda。您必须检查 Anaconda 用于构建 hdf5 的编译器是什么并使用它。
最简单的解决方法是如果只缺少 DYLD_LIBRARY_PATH
到 /Users/Ajay/anaconda/lib
的路径。尝试
DYLD_LIBRARY_PATH=/Users/Ajay/anaconda/lib ./a.out
如需进一步信息,请提供
的输出
ls /Users/Ajay/anaconda/lib | grep hdf5
h5cc -showconfig
我正在尝试执行 c 程序来执行 HDF5 基本代码。那是在下面。
/*
* This example illustrates how to create a dataset that is a 4 x 6
* array. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
hid_t file_id, dataset_id, dataspace_id; /* identifiers */
hsize_t dims[2];
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create the data space for the dataset. */
dims[0] = 4;
dims[1] = 6;
dataspace_id = H5Screate_simple(2, dims, NULL);
/* Create the dataset. */
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* End access to the dataset and release resources used by it. */
status = H5Dclose(dataset_id);
/* Terminate access to the data space. */
status = H5Sclose(dataspace_id);
/* Close the file. */
status = H5Fclose(file_id);
}
我没有收到任何编译时错误,但是 运行 时间错误说它无法加载某些库。错误粘贴在下面 -
19:36:27 macOS_ ⚡ h5cc -show myprog.c clang -arch x86_64 myprog.c -L/Users/Ajay/anaconda/lib -lhdf5_hl -lhdf5 -arch x86_64 -lpthread -lz -ldl -lm 19:36:33 macOS_ ⚡ ./a.out dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib Referenced from: /Users/Ajay/opensource/HDF5-Examples/./a.out Reason: image not found Abort trap: 6 19:36:35 macOS_ ⚡
有关配置的更多信息 -
09:11:59 macOS_ ⚡ h5cc -showconfig SUMMARY OF THE HDF5 CONFIGURATION ================================= General Information: ------------------- HDF5 Version: 1.8.17 Configured on: Tue Aug 2 08:44:51 BST 2016 Configured by: ray@rays-Mac.local Configure mode: production Host system: i386-apple-darwin11.4.2 Uname information: Darwin rays-Mac.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64 Byte sex: little-endian Libraries: shared Installation point: /Users/Ajay/anaconda Compiling Options: ------------------ Compilation Mode: production C Compiler: /usr/bin/clang ( Apple LLVM version 4.2 ) CFLAGS: -arch x86_64 H5_CFLAGS: -O3 AM_CFLAGS: CPPFLAGS: H5_CPPFLAGS: -DNDEBUG -UH5_DEBUG_API AM_CPPFLAGS: Shared C Library: yes Static C Library: no Statically Linked Executables: no LDFLAGS: -arch x86_64 H5_LDFLAGS: AM_LDFLAGS: Extra libraries: -lpthread -lz -ldl -lm Archiver: ar Ranlib: ranlib Debugged Packages: API Tracing: no Languages: ---------- Fortran: no C++: yes C++ Compiler: /usr/bin/clang++ ( Apple LLVM version 4.2 ) C++ Flags: -arch x86_64 H5 C++ Flags: -O3 AM C++ Flags: Shared C++ Library: yes Static C++ Library: no Features: --------- Parallel HDF5: no High Level library: yes Threadsafety: yes Default API Mapping: v18 With Deprecated Public Symbols: yes I/O filters (external): deflate(zlib) MPE: no Direct VFD: no dmalloc: no Clear file buffers before write: yes Using memory checker: no Function Stack Tracing: no Strict File Format Checks: no Optimization Instrumentation: no
库位置
09:11:56 macOS_ ⚡ ls /Users/Ajay/anaconda/lib | grep hdf5 -rwxr-xr-x 2 Ajay staff 17232 Aug 2 2016 libhdf5_hl_cpp.11.dylib -rwxr-xr-x 2 Ajay staff 123256 Aug 2 2016 libhdf5_hl.10.dylib -rwxr-xr-x 2 Ajay staff 445776 Aug 2 2016 libhdf5_cpp.12.dylib -rwxr-xr-x 2 Ajay staff 2622428 Aug 2 2016 libhdf5.10.dylib lrwxr-xr-x 1 Ajay staff 20 Mar 25 09:11 libhdf5_cpp.dylib -> libhdf5_cpp.12.dylib lrwxr-xr-x 1 Ajay staff 16 Mar 25 09:11 libhdf5.dylib -> libhdf5.10.dylib -rwxr-xr-x 1 Ajay staff 1087 Mar 25 09:11 libhdf5_hl_cpp.la lrwxr-xr-x 1 Ajay staff 23 Mar 25 09:11 libhdf5_hl_cpp.dylib -> libhdf5_hl_cpp.11.dylib -rwxr-xr-x 1 Ajay staff 988 Mar 25 09:11 libhdf5_hl.la lrwxr-xr-x 1 Ajay staff 19 Mar 25 09:11 libhdf5_hl.dylib -> libhdf5_hl.10.dylib -rwxr-xr-x 1 Ajay staff 993 Mar 25 09:11 libhdf5_cpp.la -rw-r--r-- 1 Ajay staff 2243 Mar 25 09:11 libhdf5.settings -rwxr-xr-x 1 Ajay staff 937 Mar 25 09:11 libhdf5.la
Based on the comment I can now run using
DYLD_LIBRARY_PATH=/Users/Ajay/anaconda/lib ./a.out
How to make it permanent ?
我不在 Mac 上,也不使用 Anaconda。无论如何,我会尝试猜测诊断您的问题:-)
- 程序生成但不会执行。可执行文件 (
libhdf5_hl.10.dylib
) 请求的库与您系统中的库不匹配。 - 您正在使用安装了 hdf5 的 Anaconda。您必须检查 Anaconda 用于构建 hdf5 的编译器是什么并使用它。
最简单的解决方法是如果只缺少 DYLD_LIBRARY_PATH
到 /Users/Ajay/anaconda/lib
的路径。尝试
DYLD_LIBRARY_PATH=/Users/Ajay/anaconda/lib ./a.out
如需进一步信息,请提供
的输出ls /Users/Ajay/anaconda/lib | grep hdf5
h5cc -showconfig