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)
    
    # https://gist.github.com/scienceopen/9f88bbe4841ea67aa692f7395bb38bfe
    
    add_executable(myprog ../myprog.c)
    
    find_package(HDF5 REQUIRED)
    include_directories(${HDF5_INCLUDE_DIR})
    target_link_libraries(myprog ${HDF5_C_LIBRARIES})
    

HDF5 C example

Tags:

Categories:

Updated:

Leave a Comment