C++ 致命错误:H5Cpp.h:没有这样的文件或目录
我正在尝试用HDF5库编译一个应用程序。我通过ubuntus 18.04包管理器安装了lib。我的CMakeLists看起来像C++ 致命错误:H5Cpp.h:没有这样的文件或目录,c++,hdf5,C++,Hdf5,我正在尝试用HDF5库编译一个应用程序。我通过ubuntus 18.04包管理器安装了lib。我的CMakeLists看起来像 cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(hdf) find_package(HDF5 REQUIRED COMPONENTS C CXX) add_executable(hdf hdf.cpp) target_link_libraries(hdf ${HDF5_HL
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(hdf)
find_package(HDF5 REQUIRED COMPONENTS C CXX)
add_executable(hdf hdf.cpp)
target_link_libraries(hdf ${HDF5_HL_LIBRARIES} ${HDF5_CXX_LIBRARIES} ${HDF5_LIBRARIES})
set_property(TARGET hdf PROPERTY CXX_STANDARD 17)
message(STATUS "INCLUDE LOCATION" ${HDF5_INCLUDE_DIRS})
message(STATUS "version" ${HDF5_VERSION})
message(STATUS "DEFINITIONS" ${HDF5_DEFINITIONS})
message(STATUS "LIBRARIES" ${HDF5_LIBRARIES})
message(STATUS "HL_LIBRARIES" ${HDF5_HL_LIBRARIES})
运行cmake,输出将产生
HDF5: Using hdf5 compiler wrapper to determine C configuration
-- HDF5: Using hdf5 compiler wrapper to determine CXX configuration
-- Found HDF5: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_cpp.so;/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so;/usr/lib/x86_64-linux-gnu/libpthread.so;/usr/lib/x86_64-linux-gnu/libsz.so;/usr/lib/x86_64-linux-gnu/libz.so;/usr/lib/x86_64-linux-gnu/libdl.so;/usr/lib/x86_64-linux-gnu/libm.so (found version "1.10.0.1") found components: C CXX
-- INCLUDE LOCATION/usr/include/hdf5/serial
-- version1.10.0.1
-- DEFINITIONS-D_FORTIFY_SOURCE=2
-- LIBRARIES/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_cpp.so/usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so/usr/lib/x86_64-linux-gnu/libpthread.so/usr/lib/x86_64-linux-gnu/libsz.so/usr/lib/x86_64-linux-gnu/libz.so/usr/lib/x86_64-linux-gnu/libdl.so/usr/lib/x86_64-linux-gnu/libm.so
-- HL_LIBRARIES
显然所有的文件都找到了
但是,如果我不打算编译一个简单的示例,并将依赖项包含在
#include "H5Cpp.h"
我明白了
fatal error: H5Cpp.h: No such file or directory
#include "H5Cpp.h"
为什么呢?感谢您的帮助您必须明确地将标题位置添加到您的CMakeLists.txt:
include_directories(${HDF5_INCLUDE_DIRS})
有关更多详细信息,请参阅的文档。HDF5标头是否安装在标准位置?看起来不是这样,也许它们安装在标准位置的子目录中?或者可能它们根本没有安装在标准位置,在这种情况下,您需要使用中指定的HDF5\u INCLUDE\u DIRS。你可以添加目录,例如…,我刚想出来。我已经习惯了linklibraries部分中处理这两个方面的::语法,以至于在以旧方式链接libs时,我忘记了这一点。非常感谢。