Conflict with HDF5?

Hi,

Hoping I have chosen the best category to explain my problem.

Context

I am willing to develop a small project using many libraries including HDF5 library from hdfgroup and the OTB.

Configuration setup

My system: Windows10 and Ubuntu 18.04
Version of the OTB: 7.1
*I installed the OTB with the binaries given and also SuperBuild

Description of my issue

When I am compiling a small project using that includes these two libraries, some errors appears on the header files of hdfgroup library that do not raise when I am not including OTB.
Therefore, I think there is a conflict between hdfgroup library and the HDF5 library and header files that are provided with OTB.

I tried a workaround by building without HDF5 the OTB (using the SuperBuild install). I have no trouble doing this on Ubuntu system.
However, on Windows 10, it is not compiling since it fails all the tests (PNG files, etc). Possible reason is that it is “forced” to use the MinGW gcc compiler (while I have a 64 bit system) in spite of the cmake configuration that points the C compiler to Visual Studio.

Hello,

Can you provide the cmake configuration command you are using, and error logs ? I will try to reproduce your error.

On Windows, OTB is tested using VS studio (command line 2019). I don’t have any experience building it with MinGW but it should be possible.

Cédric

Dear Cedric,

Here is my CMakeLists.txt (note that I added HDF_DIR as en Environment Variable)

#find_package(Qt5 COMPONENTS Widgets PrintSupport REQUIRED)

# Find the QtWidgets library
find_package(Qt5Widgets)
find_package(Qt5PrintSupport)

add_compile_definitions(QCUSTOMPLOT_USE_LIBRARY)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    message(${CMAKE_BUILD_TYPE})
    if (UNIX)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/libqcustomplotd.so")
    elseif(WIN32)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/qcustomplotd2.lib")
    endif()
else()
    message(${CMAKE_BUILD_TYPE})
    if (UNIX)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/libqcustomplot.so")
    elseif(WIN32)
        set(LINK_LIB_PLOT "${CMAKE_CURRENT_SOURCE_DIR}/qcustomplot2.lib")
    endif()
endif()

if (UNIX)
    # set manually the path to OTB directory
    set(OTB_DIR "~/OTB/superbuild_install/lib/cmake/OTB-7.1/")
endif()

set (FIND_HDF_COMPONENTS C CXX HL HLCXX  static)
find_package (HDF5 NAMES "hdf5" COMPONENTS ${FIND_HDF_COMPONENTS})
if (HDF5_FOUND)
  if (HDF5_static_C_FOUND)
    set (LINK_LIBS ${LINK_LIBS} ${HDF5_C_STATIC_LIBRARY})
  endif ()
  if (HDF5_static_CXX_FOUND)
    set (LINK_LIBS ${LINK_LIBS} ${HDF5_CXX_STATIC_LIBRARY})
  endif ()
else ()
  message (FATAL_ERROR " HDF5 is Required")
endif ()

find_package(OTB)
if(OTB_FOUND)
  include(${OTB_USE_FILE})
else(OTB_FOUND)
  message(FATAL_ERROR "Cannot build OTB project without OTB.  Please set OTB_DIR.")
endif(OTB_FOUND)
message("OTB : ${OTB_LIBRARIES}")

if (UNIX)
    find_package(Armadillo REQUIRED)
elseif (WIN32)
    set (ARMADILLO_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include_arma")
    set (ARMADILLO_LIBRARIES "${PROJECT_SOURCE_DIR}/ext_lib")
endif()
include_directories(${HDF5_INCLUDE_DIR} ${ARMADILLO_INCLUDE_DIRS})
add_library(libUnmix SHARED
  include/libUnmix_global.h
  src/libImage.cpp
  include/libImage.h
  src/libpixelsynth.cpp
  include/libpixelsynth.h
  src/libmcmc.cpp
  include/libmcmc.h
  src/libgraph.cpp
  include/libgraph.h
  include/qcustomplot.h
  include/unmixing.h
  include/readH5File.h
)
#file(GLOB_RECURSE LIBUNMIX_INCLUDE_FILES )
target_link_libraries (libUnmix PRIVATE Qt5::Widgets Qt5::PrintSupport ${LINK_LIBS} ${HDF5_CXX_STATIC_LIBRARY} ${OTB_LIBRARIES} ${ARMADILLO_LIBRARIES} ${LINK_LIB_PLOT})
#target_compile_definitions(libUnmix PRIVATE LIBUNMIX_LIBRARY)
set_target_properties(libUnmix PROPERTIES PUBLIC_HEADER "include/qcustomplot.h;include/unmixing.h;include/libImage.h;include/libpixelsynth.h;include/libmcmc.h;include/libgraph.h;include/libUnmix_global.h;include/readH5File.h")

install(TARGETS libUnmix
  # IMPORTANT: Add the libUnmix library to the "export-set"
  EXPORT libUnmixTargets
  LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT shlib
PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR}
COMPONENT dev)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    message(${CMAKE_BUILD_TYPE})
    if (UNIX)
        install(FILES "libqcustomplotd.so" DESTINATION ${INSTALL_LIB_DIR})
    elseif(WIN32)
        install(FILES "qcustomplotd2.dll" DESTINATION ${INSTALL_LIB_DIR})
    endif()
else()
    message(${CMAKE_BUILD_TYPE})
    if (UNIX)
        install(FILES "libqcustomplot.so" DESTINATION ${INSTALL_LIB_DIR})
    elseif(WIN32)
        install(FILES "qcustomplot2.dll" DESTINATION ${INSTALL_LIB_DIR})
    endif()
endif()

For the SuperBuild, I have finally managed to build almost entirely the soft but today I am stuck with the OTB module (last one I hope) because it cannot find the SWIG module today (on Friday it was another module). And I used QtCreator with the MSVC builder.

Since I am using Visual Studio 2019 compiler in Qt Creator and since I noticed the Boost version coming with the SuperBuild is 1.69, I am starting to wonder if all my problems come from this fact.

I can confirm the super-build installation without using the hdf5 that comes with it makes my program build without errors.

But now, I have some std::bad_alloc when trying to read an image file, even in a simple Hello World program.