简单的HDF5 C++问题



我正在尝试使用执行一个基本的C++脚本(此处(。我相信我已经使用正确安装了HDF5库

sudo apt install libhdf5-dev

当我第一次尝试使用编译代码时

g++ hdf5_simple.cpp -lhdf5 -lhdf5_cpp -o hdf5_simple

我得到了:

hdf5_simple.cpp:3:10: fatal error: H5Cpp.h: No such file or directory

很简单,我尝试:

g++ -I/usr/include/hdf5/serial/ hdf5_simple.cpp -lhdf5 -lhdf5_cpp -o hdf5_simple

它没有问题,但当我尝试运行它时,它得到了:

The HDF5 header files used to compile this application do not match
the version used by the HDF5 library to which this application is linked.
Data corruption or segmentation faults may occur if the application continues.
This can happen when an application was compiled by one version of HDF5 but
linked with a different version of static or shared HDF5 library.
You should recompile the application or check your shared library related
settings such as 'LD_LIBRARY_PATH'.
You can, at your own risk, disable this warning by setting the environment
variable 'HDF5_DISABLE_VERSION_CHECK' to a value of '1'.
Setting it to 2 or higher will suppress the warning messages totally.
Headers are 1.10.4, library is 1.13.0
SUMMARY OF THE HDF5 CONFIGURATION
=================================
General Information:
-------------------
HDF5 Version: 1.13.0
Configured on: Wed Dec 22 18:04:31 UTC 2021
Configured by: ***@***
Host system: x86_64-unknown-linux-gnu
Uname information: Linux *** 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Byte sex: little-endian
Installation point: /usr/local/hdf5
Compiling Options:
------------------
Build Mode: production
Debugging Symbols: no
Asserts: no
Profiling: no
Optimization Level: high
Linking Options:
----------------
Libraries: static, shared
Statically Linked Executables: 
LDFLAGS: 
H5_LDFLAGS: 
AM_LDFLAGS: 
Extra libraries: -lz -ldl -lm 
Archiver: ar
AR_FLAGS: cr
Ranlib: ranlib
Languages:
----------
C: yes
C Compiler: /usr/bin/mpicc ( MPICH version 3.3.2 Configured with: ../src/configure -v --with-pkgversion='Ubuntu 8.4.0-3ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu built with gcc version 8.4.0 (Ubuntu 8.4.0-3ubuntu2))
CPPFLAGS: 
H5_CPPFLAGS: -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L   -DNDEBUG -UH5_DEBUG_API
AM_CPPFLAGS: 
C Flags: 
H5 C Flags:  -std=c99  -Wall -Wcast-qual -Wconversion -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-include-dirs -Wno-c++-compat -Wno-format-nonliteral -Wshadow -Wundef -Wwrite-strings -pedantic -Wlarger-than=2560 -Wlogical-op -Wframe-larger-than=16384 -Wpacked-bitfield-compat -Wsync-nand -Wstrict-overflow=5 -Wno-unsuffixed-float-constants -Wdouble-promotion -Wtrampolines -Wstack-usage=8192 -Wmaybe-uninitialized -Wdate-time -Warray-bounds=2 -Wc99-c11-compat -Wduplicated-cond -Whsa -Wnormalized -Wnull-dereference -Wunused-const-variable -Walloca -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=1 -Wrestrict -Wattribute-alias -Wcast-align=strict -Wshift-overflow=2 -fstdarg-opt  -s  -Wbad-function-cast -Wimplicit-function-declaration -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-sign -Wpointer-to-int-cast -Wint-to-pointer-cast -Wredundant-decls -Wstrict-prototypes -Wswitch -Wunused-function -Wunused-variable -Wunused-parameter -Wcast-align -Wunused-but-set-variable -Wformat -Wincompatible-pointer-types -Wint-conversion -Wshadow -Wcast-function-type -Wmaybe-uninitialized -Wno-aggregate-return -Wno-inline -Wno-missing-format-attribute -Wno-missing-noreturn -Wno-overlength-strings -Wno-jump-misses-init -Wno-suggest-attribute=const -Wno-suggest-attribute=noreturn -Wno-suggest-attribute=pure -Wno-suggest-attribute=format -Wno-suggest-attribute=cold -Wno-suggest-attribute=malloc -O3
AM C Flags: 
Shared C Library: yes
Static C Library: yes

Fortran: no
C++: no
Java: no

Features:
---------
Parallel HDF5: yes
Parallel Filtered Dataset Writes: yes
Large Parallel I/O: yes
High-level library: yes
Dimension scales w/ new references: no
Build HDF5 Tests: yes
Build HDF5 Tools: yes
Threadsafety: no
Default API mapping: v114
With deprecated public symbols: yes
I/O filters (external): deflate(zlib)
MPE: 
Map (H5M) API: no
Direct VFD: no
Mirror VFD: no
(Read-Only) S3 VFD: no
(Read-Only) HDFS VFD: no
dmalloc: no
Packages w/ extra debug output: none
API tracing: no
Using memory checker: no
Memory allocation sanity checks: no
Function stack tracing: no
Use file locking: best-effort
Strict file format checks: no
Optimization instrumentation: no
Bye...
Aborted (core dumped)

根据警告顶部的注释,我添加了#define DF5_DISABLE_VERSION_CHECK 1并重新编译,出现了相同的警告。然后我尝试使用export LD_LIBRARY_PATH="/usr/include/hdf5/serial/"将路径添加到LD_LIBRARY_path,但仍然没有成功。

我不确定出了什么问题。如有任何帮助,我们将不胜感激。

试试这个:

g++ `pkg-config --cflags hdf5-serial` hdf5_simple.cpp `pkg-config --libs hdf5-serial` -lhdf5_cpp -o hdf5_simple

该命令将允许您针对C++单线程版本构建程序。

由于已经将hdf5移植到Node.js(我是Node.js中gdal-async的作者(,我可以证明它有一些可怕的怪癖:它有两个非常重要的编译选项,线程安全选项和C++API。这两个是不兼容的,当两者都启用时,库存tarball将拒绝构建。Debian/Ubuuntu团队竭尽全力让你同时使用它们——只要不是同时使用——要么是C++(他们称之为高级API(,要么是多线程。

似乎这还不够,正如我从您的配置中看到的那样,您似乎还在上面混合了启用MPI的版本。

不要禁用任何警告和检查,要非常小心你的程序链接到的内容,否则你会在运行时遇到一些非常糟糕的意外。

相关内容

  • 没有找到相关文章

最新更新