Page MenuHomePhabricator

Cannot build module DataTypesExt becasue lz4 is not linked by CMake
Closed, ResolvedPublic

Description

I am trying to build MITK on linux using CMake. During the build it fails when trying to link DataTypesExt it reports LZ4_decompress_safe and LZ4_compress_default as undefined references. When I compile with make VERBOSE=1, I can also see that the LZ4 library is not linked.

The LZ4 library has been successfully compiled by CMake and there is a liblz4.so file in ep/lib64,

As a hotfix, I manually compiled MitkDataTypes.so by simply inserting ../../../ep/lib64/liblz4.so in the list of libraries for the call to g++ that make was going to run. By doing this, I could complete the compilation of MITK.

I'm using:

  • Scientific Linux release 7.7 (Nitrogen) (x86_64)
  • CMake version 1.21.3
  • gcc (GCC) 8.3.0
  • g++ (GCC) 8.3.0
  • Python 3.8.4

Please let me know if there is any other info I can provide.

Event Timeline

kislinsk edited projects, added MITK (v2021.10); removed MITK.
kislinsk added a subscriber: kislinsk.

Thanks for the comprehensive report. Can you do me a favor and add message(FATAL_ERROR "include dirs: ${lz4_INCLUDE_DIR} libraries: ${lz4_LIBRARIES}") as last line to CMake/PackageDepends/MITK_lz4_Config.cmake and configure MITK (not superbuild) to get the output?

kislinsk moved this task from Backlog to Cycle on the MITK (v2021.10) board.

Oh, I think I might have found the issue. Ignore the comment above and in CMake/Findlz4.cmake please add lib64 to the PATH_SUFFIXES of the two calls to find_library() in lines 11 and 18 like PATH_SUFFIXES lib lib64. Does it work?

Thank you very much for your quick response.

I tried adding lib64 as you suggested, but it sadly did not fix the issue. The error looks to be the same: liblz4.so is not added during linking.
Here's the output from what you suggested in your first comment:

CMake Error at CMake/PackageDepends/MITK_lz4_Config.cmake:3 (message):
  include dirs: /work1/patmjen/MITK/MITK-superbuild-test/ep/include
  libraries:
  optimized;/work1/patmjen/MITK/MITK-superbuild-test/ep/lib64/liblz4.so
Call Stack (most recent call first):
  CMake/mitkFunctionUseModules.cmake:52 (include)
  CMake/mitkFunctionUseModules.cmake:133 (_include_package_config)
  CMake/mitkFunctionCreateModule.cmake:605 (mitk_use_modules)
  Modules/DataTypesExt/CMakeLists.txt:1 (mitk_create_module)

Just in case, I am at commit 895486021524908ada2cd5c5978120d66678ec45 (HEAD -> develop, origin/develop, origin/HEAD).
Here's a full git diff:

diff --git a/CMake/Findlz4.cmake b/CMake/Findlz4.cmake
index a79f05ade4..e9c68dccc4 100644
--- a/CMake/Findlz4.cmake
+++ b/CMake/Findlz4.cmake
@@ -8,14 +8,14 @@ mark_as_advanced(lz4_INCLUDE_DIR)

 find_library(lz4_LIBRARY_RELEASE lz4
   PATHS ${MITK_EXTERNAL_PROJECT_PREFIX}
-  PATH_SUFFIXES lib
+  PATH_SUFFIXES lib lib64
   NO_DEFAULT_PATH)
 mark_as_advanced(lz4_LIBRARY_RELEASE)


 find_library(lz4_LIBRARY_DEBUG lz4d
   PATHS ${MITK_EXTERNAL_PROJECT_PREFIX}
-  PATH_SUFFIXES lib
+  PATH_SUFFIXES lib lib64
   NO_DEFAULT_PATH)
 mark_as_advanced(lz4_LIBRARY_DEBUG)

diff --git a/CMake/PackageDepends/MITK_lz4_Config.cmake b/CMake/PackageDepends/MITK_lz4_Config.cmake
index b9b2b8ff86..afadc3756d 100644
--- a/CMake/PackageDepends/MITK_lz4_Config.cmake
+++ b/CMake/PackageDepends/MITK_lz4_Config.cmake
@@ -1,2 +1,3 @@
 list(APPEND ALL_INCLUDE_DIRECTORIES ${lz4_INCLUDE_DIR})
 list(APPEND ALL_LIBRARIES ${lz4_LIBRARIES})
+message(FATAL_ERROR "include dirs: ${lz4_INCLUDE_DIR} libraries: ${lz4_LIBRARIES}")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 74ac3443a8..561fde1809 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,9 @@ cmake_policy(SET CMP0091 OLD)
 # Superbuild Option - Enabled by default
 #-----------------------------------------------------------------------------

+set(CMAKE_C_COMPILER gcc)
+set(CMAKE_CXX_COMPILER g++)
+
 option(MITK_USE_SUPERBUILD "Build MITK and the projects it depends on via SuperBuild.cmake." ON)

 if(MITK_USE_SUPERBUILD)
@@ -252,8 +255,8 @@ endforeach()

 option(MITK_USE_BLUEBERRY "Build the BlueBerry platform" ON)
 option(MITK_USE_OpenCL "Use OpenCL GPU-Computing library" OFF)
-option(MITK_USE_OpenMP "Use OpenMP" OFF)
-option(MITK_USE_Python3 "Use Python 3" OFF)
+option(MITK_USE_OpenMP "Use OpenMP" ON)
+option(MITK_USE_Python3 "Use Python 3" ON)

 #-----------------------------------------------------------------------------
# Build configurations
@@ -326,7 +329,7 @@ if(MITK_USE_Qt5)
         endif()
       endif()
     else()
-      set(_dir_candidates ~/Qt)
+      set(_dir_candidates /work1/patmjen/Qt)

       if(APPLE)
         set(_compilers clang)

Thanks for giving it a try. I see that optimized;/work1/patmjen/MITK/MITK-superbuild-test/ep/lib64/liblz4.so is indeed added to the dependencies. So it is strange that it is not picked up by the linker. Or, did you do a Debug build? That would explain it at least since there is only a library specified for Release builds.

edit: That must be the issue. Having another look at our Findlz4.cmake, it wrongly assumes that the debug name of the lib would always be lz4d instead of lz4 but that only makes really sense on Windows. I'll fix it today or this week.

Deleted branch from rMITK MITK: bugfix/T28706-LZ4DebugUnix.

Seems like you were right. I was doing a Debug build, yes. Changing the lib name to lz4 instead of lz4d fixed the issue on my end too.

Thank you very much for the assistance.