potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
599 stars 79 forks source link

Problems building clingo for static linking #451

Closed sthiele closed 11 months ago

sthiele commented 11 months ago

The following command line for building clingo for static linking (paths may differ) used to work for older clingo versions.

cd "build" && CMAKE_PREFIX_PATH="" "cmake" "-Wdev" "--debug-output" "/home/sthiele/Projects/clingo-sys/clingo" "-DCLINGO_BUILD_SHARED=OFF" "-DCLINGO_BUILD_STATIC=ON" "-DCLINGO_MANAGE_RPATH=OFF" "-DCLINGO_BUILD_WITH_PYTHON=OFF" "-DCLINGO_BUILD_WITH_LUA=OFF" "-DCLINGO_INSTALL_LIB=ON" "-DCLINGO_BUILD_APPS=OFF" "-DCLASP_BUILD_APP=OFF" "-DCMAKE_INSTALL_PREFIX=/home/sthiele/Projects/clingo-sys/target/debug/build/clingo-sys-f58becaeaad2395c/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" "-Wno-dev"

But with clingo 5.6.2 I get the following error message.

❯ cd "build" && CMAKE_PREFIX_PATH="" "cmake" "-Wdev" "--debug-output" "/home/sthiele/Projects/clingo-sys/clingo" "-DCLINGO_BUILD_SHARED=OFF" "-DCLINGO_BUILD_STATIC=ON" "-DCLINGO_MANAGE_RPATH=OFF" "-DCLINGO_BUILD_WITH_PYTHON=OFF" "-DCLINGO_BUILD_WITH_LUA=OFF" "-DCLINGO_INSTALL_LIB=ON" "-DCLINGO_BUILD_APPS=OFF" "-DCLASP_BUILD_APP=OFF" "-DCMAKE_INSTALL_PREFIX=/home/sthiele/Projects/clingo-sys/target/debug/build/clingo-sys-f58becaeaad2395c/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_C_COMPILER=/usr/bin/cc" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/c++" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -fPIC -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/cc" "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON" "-Wno-dev"
Running with debug output on.
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/third_party
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/clasp
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
CMake Deprecation Warning at clasp/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
-- Potassco is not installed - using local copy
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
CMake Deprecation Warning at clasp/libpotassco/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco/src
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco/CMakeLists.txt
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
   Called from: [4]     /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake
                [3]     /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake
                [2]     /usr/share/cmake/Modules/FindDoxygen.cmake
                [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo/clasp
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/clasp/src
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo/clasp
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
   Called from: [4]     /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake
                [3]     /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake
                [2]     /usr/share/cmake/Modules/FindDoxygen.cmake
                [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/libreify
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/libgringo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Entering             /home/sthiele/Projects/clingo-sys/clingo/libclingo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
   Returning to         /home/sthiele/Projects/clingo-sys/clingo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
-- Configuring done (0.2s)
-- Generating /home/sthiele/Projects/clingo-sys/build
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/third_party
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/third_party/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/clasp
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/clasp/libpotassco
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/clasp/libpotassco/src
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/libpotassco/src/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/clasp/src
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/clasp/src/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/libreify
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libreify/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/libgringo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libgringo/CMakeLists.txt
CMake Error: install(EXPORT "ClingoTargets" ...) includes target "libgringo" which requires target "ordered_map" that is not in any export set.
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libclingo/CMakeLists.txt
CMake Error: install(EXPORT "ClingoTargets" ...) includes target "libgringo" which requires target "hopscotch_map" that is not in any export set.
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libclingo/CMakeLists.txt
CMake Error: install(EXPORT "ClingoTargets" ...) includes target "libgringo" which requires target "sparse_map" that is not in any export set.
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libclingo/CMakeLists.txt
CMake Error: install(EXPORT "ClingoTargets" ...) includes target "libgringo" which requires target "optional" that is not in any export set.
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libclingo/CMakeLists.txt
CMake Error: install(EXPORT "ClingoTargets" ...) includes target "libgringo" which requires target "variant" that is not in any export set.
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libclingo/CMakeLists.txt
-- Generating /home/sthiele/Projects/clingo-sys/build/libclingo
   Called from: [1]     /home/sthiele/Projects/clingo-sys/clingo/libclingo/CMakeLists.txt
-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

To reproduce you can also run (you need the clingo build dependencies + rustc/cargo ect. installed)

git clone https://github.com/potassco/clingo-sys.git
cd clingo-sys
git checkout st/update-clingo
git submodule update --init --recursive
cd clingo
git checkout v5.6.2
cd ..
cargo build --features static-linking --verbose

The cmake relevant part in the build.rs is here: https://github.com/potassco/clingo-sys/blob/3b1c2619e96bc26b3ea8838b720f8f0f437d7884/build.rs#L48-L59

rkaminsk commented 11 months ago

You can fix the error by installing further libraries. See the following patch:

diff --git a/libclingo/CMakeLists.txt b/libclingo/CMakeLists.txt
index 1d70ba56..61bda5f1 100644
--- a/libclingo/CMakeLists.txt
+++ b/libclingo/CMakeLists.txt
@@ -67,7 +67,7 @@ if ((CLINGO_BUILD_SHARED OR CLINGO_INSTALL_LIB) AND NOT CLINGO_BUILD_WITH_PYTHON
     if (CLINGO_BUILD_SHARED)
         set_target_properties(libclingo PROPERTIES SOVERSION 4 VERSION 4.0)
     else()
-        list(APPEND clingo_targets libgringo libreify)
+        list(APPEND clingo_targets libgringo libreify ordered_map hopscotch_map sparse_map optional variant)
     endif()

     install(TARGETS ${clingo_targets}