找不到 HDF5(缺少:HDF5_LIBRARIES CXX)(找到版本“1.10.7”)

问题描述 投票:0回答:1

我在基于 C++ 的软件中使用 HDF5,该软件是使用 CMake 构建的。

我曾经有两个 HDF5 版本,一个来自 Anaconda 附带的 h5py (1.14.x),另一个是使用 apt (1.10.x) 安装时附带的。

这种不匹配导致了错误

libhdf5 undefined reference to curl_global_init@CURL_OPENSSL_4
,我尝试通过删除 HDF5 库并卸载 HDf5 来修复该错误。

现在我重新安装了所有东西,但我什至无法达到以前的状态。

尝试构建时,我收到以下错误:

cmake -B./build/                                                                                                                                                            
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMAKE_SOURCE_DIR: /home/ac141173/repos/ResoBee
-- HDF5 CXX compiler wrapper is unable to compile a minimal HDF5 program.
CMake Error at /usr/local/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find HDF5 (missing: HDF5_LIBRARIES CXX) (found version "1.10.7")
Call Stack (most recent call first):
  /usr/local/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/share/cmake-3.24/Modules/FindHDF5.cmake:1007 (find_package_handle_standard_args)
  CMakeLists.txt:59 (find_package)


-- Configuring incomplete, errors occurred!

由于某种原因,CMake 无法再找到任何 HDF5 库。

当激活带有 h5py 的 conda 环境时,

h5cc -showconfig
会产生:

        SUMMARY OF THE HDF5 CONFIGURATION
        =================================

General Information:
-------------------
                   HDF5 Version: 1.14.2
                  Configured on: Sun Aug 20 20:09:14 UTC 2023
                  Configured by: conda@8701a29b7fa1
                    Host system: x86_64-conda-linux-gnu
              Uname information: Linux 8701a29b7fa1 5.15.0-1041-azure #48-Ubuntu SMP Tue Jun 20 20:34:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
                       Byte sex: little-endian
             Installation point: /home/path/to/conda/env

Compiling Options:
------------------
                     Build Mode: production
              Debugging Symbols: no
                        Asserts: no
                      Profiling: no
             Optimization Level: high

Linking Options:
----------------
                      Libraries: shared
  Statically Linked Executables: 
                        LDFLAGS: -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,--gc-sections -Wl,--allow-shlib-undefined -Wl,-rpath,/home/path/to/conda/env/lib -Wl,-rpath-link,/home/path/to/conda/env/lib -L/home/path/to/conda/env/lib
                     H5_LDFLAGS: 
                     AM_LDFLAGS:  -L/home/path/to/conda/env/lib -L/home/path/to/conda/env/lib
                Extra libraries: -lcrypto -lcurl -lpthread -lsz -lz -ldl -lm 
                       Archiver: /home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/_build_env/bin/x86_64-conda-linux-gnu-ar
                       AR_FLAGS: cr
                         Ranlib: /home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/_build_env/bin/x86_64-conda-linux-gnu-ranlib

Languages:
----------
                              C: yes
                     C Compiler: /home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/_build_env/bin/x86_64-conda-linux-gnu-cc
                       CPPFLAGS: -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/path/to/conda/env/include
                    H5_CPPFLAGS: -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L   -DNDEBUG -UH5_DEBUG_API -I/home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/work/src/H5FDsubfiling
                    AM_CPPFLAGS:  -I/home/path/to/conda/env/include -I/home/path/to/conda/env/include
                        C Flags: -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/path/to/conda/env/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/work=/usr/local/src/conda/hdf5-1.14.2 -fdebug-prefix-map=/home/path/to/conda/env=/usr/local/src/conda-prefix
                     H5 C Flags:  -std=c99  -Wall -Wcast-qual -Wconversion -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-include-dirs -Wshadow -Wundef -Wwrite-strings -pedantic -Wno-c++-compat -Wlarger-than=2560 -Wlogical-op -Wframe-larger-than=16384 -Wpacked-bitfield-compat -Wsync-nand -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 -Wattribute-alias -Wcast-align=strict -Wshift-overflow=2 -Wattribute-alias=2 -Wmissing-profile -Wc11-c2x-compat -fstdarg-opt -fdiagnostics-urls=never -fno-diagnostics-color -s  -Wbad-function-cast -Wcast-align -Wformat -Wimplicit-function-declaration -Wint-to-pointer-cast -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-sign -Wpointer-to-int-cast -Wredundant-decls -Wstrict-prototypes -Wswitch -Wunused-but-set-variable -Wunused-variable -Wunused-function -Wunused-parameter -Wincompatible-pointer-types -Wint-conversion -Wshadow -Wrestrict -Wcast-function-type -Wmaybe-uninitialized -Wno-aggregate-return -Wno-inline -Wno-missing-format-attribute -Wno-missing-noreturn -Wno-overlength-strings -Wno-jump-misses-init -Wstrict-overflow=2 -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: no


                        Fortran: yes
               Fortran Compiler: /home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/_build_env/bin/x86_64-conda-linux-gnu-gfortran
                  Fortran Flags: 
               H5 Fortran Flags:  -std=f2008  -Waliasing -Wall -Wcharacter-truncation -Wextra -Wimplicit-interface -Wsurprising -Wunderflow -pedantic -Wintrinsics-std -Wimplicit-procedure -Wreal-q-constant -Wfunction-elimination -Wrealloc-lhs -Wrealloc-lhs-all -Wno-c-binding-type -Winteger-division -Wfrontend-loop-interchange  -fdiagnostics-urls=never -fno-diagnostics-color -s  -Wno-unused-dummy-argument -Wno-array-temporaries -O3
               AM Fortran Flags: 
         Shared Fortran Library: yes
         Static Fortran Library: no
               Module Directory: ${includedir}

                            C++: yes
                   C++ Compiler: /home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/_build_env/bin/x86_64-conda-linux-gnu-c++
                      C++ Flags: -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/path/to/conda/env/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/hdf5_1692561980689/work=/usr/local/src/conda/hdf5-1.14.2 -fdebug-prefix-map=/home/path/to/conda/env=/usr/local/src/conda-prefix
                   H5 C++ Flags:   -std=c++11 -Wall -Wcast-qual -Wconversion -Wctor-dtor-privacy -Weffc++ -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-include-dirs -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wreorder -Wshadow -Wsign-promo -Wundef -Wwrite-strings -pedantic -Wlarger-than=2560 -Wlogical-op -Wframe-larger-than=16384 -Wpacked-bitfield-compat -Wsync-nand -Wdouble-promotion -Wtrampolines -Wstack-usage=8192 -Wmaybe-uninitialized -Wdate-time -Wopenmp-simd -Warray-bounds=2 -Wduplicated-cond -Whsa -Wnormalized -Wnull-dereference -Wunused-const-variable -Walloca -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=1 -Wattribute-alias -Wcast-align=strict -Wshift-overflow=2 -Wattribute-alias=2 -Wmissing-profile -Wno-deprecated-copy -fstdarg-opt -fdiagnostics-urls=never -fno-diagnostics-color -s  -Wcast-align -Wmissing-declarations -Wpacked -Wredundant-decls -Wswitch -Wunused-but-set-variable -Wunused-function -Wunused-variable -Wunused-parameter -Wshadow -O3
                   AM C++ Flags: 
             Shared C++ Library: yes
             Static C++ Library: no

                           Java: no


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


当基础环境被激活时,就会产生

        SUMMARY OF THE HDF5 CONFIGURATION
        =================================

General Information:
-------------------
                   HDF5 Version: 1.10.7
                  Configured on: Wed, 08 Dec 2021 23:33:27 +0000
                  Configured by: Debian
                    Host system: x86_64-pc-linux-gnu
              Uname information: Debian
                       Byte sex: little-endian
             Installation point: /usr
            Flavor name: serial

Compiling Options:
------------------
                     Build Mode: production
              Debugging Symbols: no
                        Asserts: no
                      Profiling: no
             Optimization Level: high

Linking Options:
----------------
                      Libraries: static, shared
  Statically Linked Executables: 
                        LDFLAGS: -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro
                     H5_LDFLAGS: -Wl,--version-script,$(top_srcdir)/debian/map_serial.ver
                     AM_LDFLAGS: 
                Extra libraries: -lcrypto -lcurl -lpthread -lsz -lz -ldl -lm 
                       Archiver: ar
                       AR_FLAGS: cr
                         Ranlib: x86_64-linux-gnu-ranlib

Languages:
----------
                              C: yes
                     C Compiler: /usr/bin/gcc
                       CPPFLAGS: -Wdate-time -D_FORTIFY_SOURCE=2
                    H5_CPPFLAGS: -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L   -DNDEBUG -UH5_DEBUG_API
                    AM_CPPFLAGS: 
                        C Flags: -g -O2 -ffile-prefix-map=$(top_srcdir)=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security
                     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 -Wimplicit-fallthrough=5 -Wrestrict -Wattribute-alias -Wcast-align=strict -Wshift-overflow=2 -Wattribute-alias=2 -Wmissing-profile -fstdarg-opt -s -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  -Werror=bad-function-cast -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=missing-declarations -Werror=missing-prototypes -Werror=nested-externs -Werror=old-style-definition -Werror=packed -Werror=pointer-sign -Werror=pointer-to-int-cast -Werror=redundant-decls -Werror=strict-prototypes -Werror=switch -Wunused-function -Wunused-variable -Wunused-parameter -Wcast-align -Wunused-but-set-variable -Wformat -Werror=incompatible-pointer-types -Werror=shadow -Wcast-function-type -Wmaybe-uninitialized
                     AM C Flags: 
               Shared C Library: yes
               Static C Library: yes


                        Fortran: yes
               Fortran Compiler: /usr/bin/gfortran
                  Fortran Flags: -g -O2 -ffile-prefix-map=$(top_srcdir)=. -flto=auto -ffat-lto-objects -fstack-protector-strong
               H5 Fortran Flags:  -std=f2008  -Waliasing -Wall -Wcharacter-truncation -Wextra -Wimplicit-interface -Wsurprising -Wunderflow -pedantic -Warray-temporaries -Wintrinsics-std -Wimplicit-procedure -Wreal-q-constant -Wfunction-elimination -Wrealloc-lhs -Wrealloc-lhs-all -Wno-c-binding-type -Wuse-without-only -Winteger-division -Wfrontend-loop-interchange  -s -O3
               AM Fortran Flags: 
         Shared Fortran Library: yes
         Static Fortran Library: yes

                            C++: yes
                   C++ Compiler: /usr/bin/g++
                      C++ Flags: -g -O2 -ffile-prefix-map=$(top_srcdir)=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security
                   H5 C++ Flags:   -Wall -Wcast-qual -Wconversion -Wctor-dtor-privacy -Weffc++ -Wextra -Wfloat-equal -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-include-dirs -Wno-format-nonliteral -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wreorder -Wshadow -Wsign-promo -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 -Wopenmp-simd -Warray-bounds=2 -Wduplicated-cond -Whsa -Wnormalized -Wnull-dereference -Wunused-const-variable -Walloca -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=1 -Wimplicit-fallthrough=5 -Wrestrict -Wattribute-alias -Wcast-align=strict -Wshift-overflow=2 -Wattribute-alias=2 -Wmissing-profile -fstdarg-opt -s -O3  -Wcast-align -Wmissing-declarations -Werror=packed -Werror=redundant-decls -Werror=switch -Wunused-but-set-variable -Werror=unused-function -Werror=unused-variable -Wunused-parameter -Werror=shadow
                   AM C++ Flags: 
             Shared C++ Library: yes
             Static C++ Library: yes

                           Java: yes
                  Java Compiler: /usr/bin/java (openjdk 11.0.13 2021-10-19)


Features:
---------
                   Parallel HDF5: no
Parallel Filtered Dataset Writes: no
              Large Parallel I/O: no
              High-level library: yes
                Build HDF5 Tests: yes
                Build HDF5 Tools: yes
                    Threadsafety: yes
             Default API mapping: v18
  With deprecated public symbols: yes
          I/O filters (external): deflate(zlib),szip(encoder)
                             MPE: no
                      Direct VFD: no
                      Mirror VFD: no
              (Read-Only) S3 VFD: yes
            (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

我尝试卸载所有库(例如 Boost 和 OpenMP)。重新安装后,Boost和OpenMP又找到了,没有任何问题,但是HDF5就找不到了。

我尝试使用

set(LD_LIBRARY_PATH)
,但这没有用。 在我的 CMakeLists.txt 文件中,我只使用:

include(FetchContent)
find_package(HDF5 REQUIRED COMPONENTS CXX)
link_directories(${HDF5_LIBRARY_DIRS})
include_directories(${HDF5_INCLUDE_DIRS})

在我的

CMakeCache.txt
中,HDF5标志如下:


//HDF5 CXX Wrapper compiler.  Used only to detect HDF5 compile
// flags.
HDF5_CXX_COMPILER_EXECUTABLE:FILEPATH=/usr/bin/h5c++

//Path to a file.
HDF5_CXX_INCLUDE_DIR:PATH=/usr/include/hdf5/serial

//HDF5 file differencing tool.
HDF5_DIFF_EXECUTABLE:FILEPATH=/usr/bin/h5diff

//The directory containing a CMake configuration file for HDF5.
HDF5_DIR:PATH=HDF5_DIR-NOTFOUND

//HDF5 library compiled with parallel IO support
HDF5_IS_PARALLEL:BOOL=FALSE

//Path to a library.
HDF5_hdf5_LIBRARY_DEBUG:FILEPATH=HDF5_hdf5_LIBRARY_DEBUG-NOTFOUND

//Path to a library.
HDF5_hdf5_LIBRARY_RELEASE:FILEPATH=HDF5_hdf5_LIBRARY_RELEASE-NOTFOUND

//Path to a library.
HDF5_hdf5_cpp_LIBRARY_DEBUG:FILEPATH=HDF5_hdf5_cpp_LIBRARY_DEBUG-NOTFOUND

//Path to a library.
HDF5_hdf5_cpp_LIBRARY_RELEASE:FILEPATH=HDF5_hdf5_cpp_LIBRARY_RELEASE-NOTFOUND

//ADVANCED property for variable: HDF5_CXX_COMPILER_EXECUTABLE
HDF5_CXX_COMPILER_EXECUTABLE-ADVANCED:INTERNAL=1
//Result of TRY_COMPILE
HDF5_CXX_COMPILER_NO_INTERROGATE:INTERNAL=FALSE
//ADVANCED property for variable: HDF5_CXX_INCLUDE_DIR
HDF5_CXX_INCLUDE_DIR-ADVANCED:INTERNAL=1
//ADVANCED property for variable: HDF5_DIFF_EXECUTABLE
HDF5_DIFF_EXECUTABLE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: HDF5_IS_PARALLEL
HDF5_IS_PARALLEL-ADVANCED:INTERNAL=1
//ADVANCED property for variable: HDF5_hdf5_LIBRARY_DEBUG
HDF5_hdf5_LIBRARY_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: HDF5_hdf5_LIBRARY_RELEASE
HDF5_hdf5_LIBRARY_RELEASE-ADVANCED:INTERNAL=1
//ADVANCED property for variable: HDF5_hdf5_cpp_LIBRARY_DEBUG
HDF5_hdf5_cpp_LIBRARY_DEBUG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: HDF5_hdf5_cpp_LIBRARY_RELEASE
HDF5_hdf5_cpp_LIBRARY_RELEASE-ADVANCED:INTERNAL=1

这表明没有找到正确的路径。

理想情况下,我可以只使用 h5py 附带的一个 HDF5 版本,以实现可重复性。 我怎样才能实现这个目标?我想我需要告诉 CMake 在哪里寻找库,但我不知道如何。但为什么以前不告诉这些信息就可以无缝运行,而现在却不能了?

谢谢您的帮助!

更新:我根据 CMakeCache.txt 路径进行了一些挖掘,发现变量 libdir 中存储的路径指向我手动删除的路径,

"${prefix}/lib/x86_64-linux-gnu"
(我自己注意:永远不要手动删除库文件夹,我假设他们将被安装):

cat /usr/bin/h5c++                                                                                                                                                           
#! /bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5.  The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the COPYING file, which can be found at the root of the source code
# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
# If you do not have access to either file, you may request a copy from
# [email protected].
#

############################################################################
##                                                                        ##
## Things You May Have to Modify:                                         ##
##                                                                        ##
## If the following paths don't point to the place were HDF5 is installed ##
## on your system (i.e., you received a binary distribution or moved the  ##
## files from the originally installed directory to another directory)    ##
## then modify them accordingly to represent the new paths.               ##
##                                                                        ##
############################################################################
prefix="/usr"
exec_prefix="${prefix}"
libdir="${prefix}/lib/x86_64-linux-gnu"
libdevdir="${prefix}/lib/x86_64-linux-gnu/hdf5/serial"
includedir="${prefix}/include/hdf5/serial"
HL="hl"
c++ cmake anaconda hdf5 h5py
1个回答
0
投票

我解决了! (不是原来的问题,而是这个问题)

解决方案是清除所有 HDF5 软件包并重新安装它们,使用

sudo apt-get remove --purge $(dpkg -l | grep 'hdf5' | awk '{print $2}')

仅使用remove不会产生一组新的配置文件,所以似乎需要purge。然后当然删除构建目录并再次构建,然后它应该可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.