为什么我在执行HDF5示例代码时遇到libhdf5_hl未加载错误?

时间:2017-03-28 00:42:39

标签: c hdf5

我正在尝试执行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);
}

我没有得到任何编译时错误,但运行时错误说它无法加载一些lib。错误粘贴在下面 -

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

lib位置

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
  
    

根据我现在可以使用的评论     DYLD_LIBRARY_PATH=/Users/Ajay/anaconda/lib ./a.out     如何永久?

  

1 个答案:

答案 0 :(得分:1)

我不在Mac上,也不使用Anaconda。我会尝试猜测 - 无论如何都要诊断你的问题: - )

  1. 程序构建但不会执行。可执行文件(libhdf5_hl.10.dylib)请求的库与系统中的库之间存在不匹配。
  2. 您使用的是Anaconda安装的hdf5。您必须检查Anaconda使用什么编译器来构建hdf5并使用它。
  3. 最简单的方法是,如果缺少的只是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