安装用于 C++ 的 HDF5

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

我正在尝试使用 HDF5 编写 C++ 程序,但我在构建过程中遇到了困难。似乎 cmake 没有找到 HDF5 库。这是我尝试过的:

main.cpp:

#include <iostream>
#include <hdf5.h>

int main(){
    std::cout << "Hello World" << std::endl;
}

CMakeLitsts.txt:

project(HelloWorld)
cmake_minimum_required(VERSION 3.27)

add_executable(hello_world main.cpp)

#  what do I have to do here? The find_package(HDF5 REQUIRED) fails as it doesnt find the HDF5 library
include_directories(${HDF5_INCLUDE_DIRS})
find_package(HDF5 REQUIRED)
target_link_libraries( hello_world ${HDF5_CXX_LIBRARIES} ${HDF5_LIBRARIES})

运行 cmake 失败并显示错误消息

Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS) (found version "")

我在文件夹

.local/hdf5
(我正在使用Ubuntu)中下载并构建了HDF5,使用

mkdir build
cd build
cmake ..
make

我缺少哪一步?我必须在另一个目录中构建它吗?

c++ cmake hdf5
1个回答
0
投票

我有一个类似的问题,修复(我不喜欢)是

  1. 将编译器定向到您构建的 include 文件夹
  2. 使用 hdf5 使用的编译器包装器

例如而不是

g++ your_code.cpp -o your_outpout.o

使用

h5c++ -I ~/hdf5_install/HDF5-1.14.3-Linux/HDF_Group/HDF5/1.14.3/include/ your_code.cpp -o your_output.o
© www.soinside.com 2019 - 2024. All rights reserved.