Linking libhdf5-dev with CMake

CMake links HDF5 into your C, C++, or Fortran program with just a few lines in your CMake file. I have an example CMake for writing network data to HDF5 in C.

We can create an even simpler example below used with a simple HDF5 read/write example:

  1. prereqs
    apt install libhdf5-dev
  2. create CMakeLists.txt
    cmake_minimum_required (VERSION 3.1) #yes, CMake 3.1 is required
    project(myproj C)
    add_executable(myprog ../myprog.c)
    find_package(HDF5 REQUIRED)
    target_link_libraries(myprog ${HDF5_C_LIBRARIES})

HDF5 C example




Leave a Comment