Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several Linux build errors introduced in 2.8.1 (Eigen3, DBus, boost::log) #13608

Closed
jmickelin opened this issue Nov 20, 2024 · 3 comments
Closed
Labels
Build Build issues

Comments

@jmickelin
Copy link
Contributor

jmickelin commented Nov 20, 2024

Description of the bug

2.8.1 introduced a number of regressions to the build process on Linux. Specifically, 2111699 saw a lot of refactoring in the CMake files, and a few dependencies were lost along the way. These problems are especially apparent on source
distributions like Nix or Gentoo, where the CMake modules for fetching dependencies from the web aren't used.

Here is a summary of my findings, and patches for solving them:

Errors

These errors showed up during my patching efforts. Obviously, since each one halts the build, later ones showed up after I fixed the earlier ones (using the solutions below).

Eigen3

The Eigen3::Eigen target is missing.

CMake log
CMake Warning (dev) at bundled_deps/admesh/CMakeLists.txt:16 (target_link_libraries):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "admesh" links to:

    Eigen3::Eigen

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at src/clipper/CMakeLists.txt:13 (target_link_libraries):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "clipper" links to:

    Eigen3::Eigen

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at src/libslic3r/CMakeLists.txt:631 (target_link_libraries):
  Target "libslic3r" links to:

    Eigen3::Eigen

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

DBus

Includes (but not libraries) for DBus are missing:

CMake log
[ 90%] Building CXX object src/slic3r/CMakeFiles/libslic3r_gui.dir/GUI/NotificationManager.cpp.o
src/slic3r/GUI/InstanceCheck.cpp:31:10: fatal error: 'dbus/dbus.h' file not found
   31 | #include <dbus/dbus.h> /* Pull in all of D-Bus headers. */
      |          ^~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/slic3r/CMakeFiles/libslic3r_gui.dir/build.make:2109: src/slic3r/CMakeFiles/libslic3r_gui.dir/GUI/InstanceCheck.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
1 warning generated.
make[1]: *** [CMakeFiles/Makefile2:1203: src/slic3r/CMakeFiles/libslic3r_gui.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

boost::log

Linker fails for boost:log, but only within tests/sla_print:

CMake log
[ 62%] Building CXX object tests/fff_print/CMakeFiles/fff_print_tests.dir/test_gaps.cpp.o
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `_test_concave_hull(std::vector<Slic3r::Polygon, tbb::detail::d1::scalable_allocator<Slic3r::Polygon> > const&, std::vector<Slic3r::ExPolygon, std::allocator<Slic3r::ExPolygon> > const&)':
tests/sla_print/sla_test_utils.cpp:299:(.text+0x4517): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `_test_concave_hull(std::vector<Slic3r::Polygon, tbb::detail::d1::scalable_allocator<Slic3r::Polygon> > const&, std::vector<Slic3r::ExPolygon, std::allocator<Slic3r::ExPolygon> > const&)':
build/tests/sla_print/include/boost/log/sources/basic_logger.hpp:460:(.text+0x4523): undefined reference to `boost::log::v2s_mt_posix::core::get_logging_enabled() const'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::sources::aux::severity_level<boost::log::v2s_mt_posix::trivial::severity_level>::set_value(boost::log::v2s_mt_posix::trivial::severity_level)':
build/tests/sla_print/include/boost/log/sources/severity_feature.hpp:137:(.text+0x4538): undefined reference to `boost::log::v2s_mt_posix::sources::aux::get_severity_level()'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex> >::open_record_unlocked<boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> > >(boost::parameter::aux::tagged_argument_list_of_1<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, boost::log::v2s_mt_posix::trivial::severity_level const> > const&)':
build/tests/sla_print/include/boost/log/sources/basic_logger.hpp:260:(.text+0x4556): undefined reference to `boost::log::v2s_mt_posix::core::open_record(boost::log::v2s_mt_posix::attribute_set const&)'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::auto_release::~auto_release()':
build/tests/sla_print/include/boost/log/sources/record_ostream.hpp:493:(.text+0x4594): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `_test_concave_hull(std::vector<Slic3r::Polygon, tbb::detail::d1::scalable_allocator<Slic3r::Polygon> > const&, std::vector<Slic3r::ExPolygon, std::allocator<Slic3r::ExPolygon> > const&)':
tests/sla_print/sla_test_utils.cpp:299:(.text+0x45a8): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::record_pump(boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>&, boost::log::v2s_mt_posix::record&)':
build/tests/sla_print/include/boost/log/sources/record_ostream.hpp:508:(.text+0x45c0): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::core::push_record(boost::log::v2s_mt_posix::record&&)':
build/tests/sla_print/include/boost/log/core/core.hpp:308:(.text+0x4622): undefined reference to `boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::auto_release::~auto_release()':
build/tests/sla_print/include/boost/log/sources/record_ostream.hpp:493:(.text+0x4ac3): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::record::reset()':
build/tests/sla_print/include/boost/log/core/record.hpp:157:(.text+0x4aec): undefined reference to `boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::core::push_record(boost::log::v2s_mt_posix::record&&)':
build/tests/sla_print/include/boost/log/core/core.hpp:308:(.text._ZN5boost3log12v2s_mt_posix3aux11record_pumpINS1_7sources18severity_logger_mtINS1_7trivial14severity_levelEEEED2Ev[_ZN5boost3log12v2s_mt_posix3aux11record_pumpINS1_7sources18severity_logger_mtINS1_7trivial14severity_levelEEEED2Ev]+0x31): undefined reference to `boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)'
ld: CMakeFiles/sla_print_tests.dir/sla_test_utils.cpp.o: in function `boost::log::v2s_mt_posix::aux::record_pump<boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level> >::auto_release::~auto_release()':
build/tests/sla_print/include/boost/log/sources/record_ostream.hpp:493:(.text._ZN5boost3log12v2s_mt_posix3aux11record_pumpINS1_7sources18severity_logger_mtINS1_7trivial14severity_levelEEEED2Ev[_ZN5boost3log12v2s_mt_posix3aux11record_pumpINS1_7sources18severity_logger_mtINS1_7trivial14severity_levelEEEED2Ev]+0x41): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
ld: build/tests/sla_print/include/boost/log/sources/record_ostream.hpp:493:(.text._ZN5boost3log12v2s_mt_posix3aux11record_pumpINS1_7sources18severity_logger_mtINS1_7trivial14severity_levelEEEED2Ev[_ZN5boost3log12v2s_mt_posix3aux11record_pumpINS1_7sources18severity_logger_mtINS1_7trivial14severity_levelEEEED2Ev]+0x55): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [tests/sla_print/CMakeFiles/sla_print_tests.dir/build.make:248: tests/sla_print/sla_print_tests] Error 1
make[1]: *** [CMakeFiles/Makefile2:1538: tests/sla_print/CMakeFiles/sla_print_tests.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

...

[ 99%] Linking CXX static library liblibslic3r_gui.a
[ 99%] Built target libslic3r_gui
make: *** [Makefile:146: all] Error 2

OpenSSL:

Linker fails for OpenSSL:

CMake log
ld: slic3r/liblibslic3r_gui.a(UserAccountCommunication.cpp.o): undefined reference to symbol 'EVP_DigestInit_ex@@OPENSSL_3.0.0'
ld: /usr/lib/libcrypto.so.3: error adding symbols: DSO missing from command line
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [src/CMakeFiles/PrusaSlicer.dir/build.make:173: src/prusa-slicer] Error 1
make[1]: *** [CMakeFiles/Makefile2:990: src/CMakeFiles/PrusaSlicer.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

Root cause analysis and solutions

Eigen3:

This was exposed after the removal of the bundled version of Eigen3. Ultimately, it is caused by the module cmake/modules/FindEigen3.cmake being ancient and not properly exporting the namespaced target (Eigen3::Eigen) but only its alias (eigen). (The build works if you replace all references to Eigen3::Eigen with just eigen, but the intent is clearly to go with the namespaced name, so let's fix that.)

The most immediate solution would be to update the module to the newest version from upstream, which properly exports the namespaced target: https://gitlab.com/libeigen/eigen/-/blob/3.4.0/cmake/FindEigen3.cmake?ref_type=tags

However, note that Eigen no longer bundles any Find*.cmake modules, in favor of using pkg-config, as explained in this PR: https://gitlab.com/libeigen/eigen/-/merge_requests/485

The way that CMake works, Find* modules take precedence over the Config ones, so even though my build environment had the .pc files present, they were masked by PrusaSlicer's module. This suggests further ways to solve this dependency:

  • One can force the Config module to take precedence by using find_package(Eigen3 CONFIG REQUIRED) as described here.
  • Alternatively, this behavior can be configured globally for all packages by passing the -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON flag to CMake.
  • Finally, you can simply delete cmake/modules/FindEigen3.cmake.

Of these four, I actually think the final one is the most elegant and future-proof. The only caveat is that I don't know how this affects builds on other platforms, since I can't test them (though I did spot some conditional imports for PkgConfig, which could cause problems if some platforms doesn't use it). For this reason, I want to suggest the first method with updating of the module instead.

DBus:

While I haven't pinpointed the exact cause, it seems that the move from explicit include_directory calls assumed that the existing invocation of ${DBUS_LIBRARIES} would be enough to pull in the includes. This does not appear to be the case. Indeed, calling CMake with the flags --trace-source=CMakeLists.txt --trace-expand flags reveals the following:

CMake log
src/slic3r/CMakeLists.txt(446):  if(MSVC )
src/slic3r/CMakeLists.txt(448):  elseif(CMAKE_SYSTEM_NAME STREQUAL Linux )
src/slic3r/CMakeLists.txt(449):  target_link_libraries(libslic3r_gui PUBLIC /usr/lib/ibdbus-1.so )
src/slic3r/CMakeLists.txt(460):  if(SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY )
src/slic3r/CMakeLists.txt(461):  add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE )
-- Adding precompiled header pchheader.hpp to target libslic3r_gui.
src/slic3r/CMakeLists.txt(467):  if(UNIX AND NOT APPLE )
src/slic3r/CMakeLists.txt(468):  find_package(GTK3 REQUIRED )

The target actually refers to a file, namely the .so. I'm not a CMake expert (who is?), so I'm not entirely clear on how one is meant to add the include flags with this module unless one's using the (now removed) include_directory call.

However, I discovered that upstream DBus actually discourages use of bespoke FindDBus modules, and that they provide modules that should work out of the box. See here for further details: https://gitlab.freedesktop.org/dbus/dbus/-/commit/d160c1a71acc157613a5fc4e1ff315d1607f66ff

So, instead of using cmake/modules/FindDBus.cmake (and calling find_package(DBus REQUIRED)), use find_package(DBus1 REQUIRED). The link can then be added using target_link_libraries(libslic3r_gui PUBLIC ${DBus1_LIBRARIES}). I have confirmed that this solves the error.

Patch:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -246,7 +246,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
     set(THREADS_PREFER_PTHREAD_FLAG ON)
     find_package(Threads REQUIRED)

-    find_package(DBus REQUIRED)
+    find_package(DBus1 REQUIRED)
 endif()

 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX)
--- a/src/slic3r/CMakeLists.txt
+++ b/src/slic3r/CMakeLists.txt
@@ -443,7 +443,7 @@ target_link_libraries(
 if (MSVC)
     target_link_libraries(libslic3r_gui PUBLIC Setupapi.lib)
 elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
-    target_link_libraries(libslic3r_gui PUBLIC ${DBUS_LIBRARIES})
+    target_link_libraries(libslic3r_gui PUBLIC ${DBus1_LIBRARIES})
 elseif (APPLE)
     target_link_libraries(libslic3r_gui PUBLIC ${DISKARBITRATION_LIBRARY} ${COREWLAN_LIBRARY})
 endif()

boost::log

This is caused by the missing dependency boost_headeronly within tests/sla_print and src/slic3r.

--- a/src/slic3r/CMakeLists.txt
+++ b/src/slic3r/CMakeLists.txt
@@ -438,6 +438,7 @@ target_link_libraries(
     NanoSVG::nanosvgrast
     stb_dxt
     fastfloat
+    boost_headeronly
 )

 if (MSVC)
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -14,6 +14,6 @@ add_library(test_common INTERFACE)
 target_include_directories(test_common INTERFACE ''${CMAKE_CURRENT_LIST_DIR})
 target_compile_definitions(test_common INTERFACE TEST_DATA_DIR=R"\(''${TEST_DATA_DIR}\)" CATCH_CONFIG_FAST_COMPILE)
-target_link_libraries(test_common INTERFACE Catch2::Catch2)
+target_link_libraries(test_common INTERFACE Catch2::Catch2 boost_headeronly)

 if (APPLE)
     target_link_libraries(test_common INTERFACE "-liconv -framework IOKit" "-framework CoreFoundation" -lc++)

OpenSSL

This was actually present starting in 2.8.0, and there is already a PR waiting for review from @Rose-David: #13080

I'll replicate the patch here for completeness:

--- a/src/slic3r/CMakeLists.txt
+++ b/src/slic3r/CMakeLists.txt
@@ -383,6 +383,7 @@ set(SLIC3R_GUI_SOURCES
 )

 find_package(NanoSVG REQUIRED)
+find_package(OpenSSL REQUIRED)

 if (APPLE)
     list(APPEND SLIC3R_GUI_SOURCES
@@ -438,6 +439,8 @@ target_link_libraries(
     NanoSVG::nanosvgrast
     stb_dxt
     fastfloat
+    OpenSSL::SSL
+    OpenSSL::Crypto
 )

 if (MSVC))

Note that the above PR also includes a patch for some missing includes, but that does not appear to be needed in my testing.

PR

I have created a PR incorporating these changes here: #13609

Version of PrusaSlicer

2.8.1

Operating system

Linux, NixOS

jmickelin added a commit to jmickelin/PrusaSlicer that referenced this issue Nov 20, 2024
This solves the build error with the missing `Eigen3::Eigen` build
target.

Partially fixes prusa3d#13608
jmickelin added a commit to jmickelin/PrusaSlicer that referenced this issue Nov 20, 2024
This solves the build error with missing headers.

Partially fixes prusa3d#13608.
jmickelin added a commit to jmickelin/PrusaSlicer that referenced this issue Nov 20, 2024
This solves the linker error about missing `boost::log` symbols.

Fixes prusa3d#13608.
@jmickelin jmickelin changed the title Several build errors introduced in 2.8.1 (Eigen3, DBus, boost::log) Several Linux build errors introduced in 2.8.1 (Eigen3, DBus, boost::log) Nov 20, 2024
@jmickelin
Copy link
Contributor Author

jmickelin commented Nov 20, 2024

Also CC @fordfrog who I see has done some similar work for the Gentoo ebuild for 2.8.0 and 2.8.1. (Specifically, I managed to solve the Eigen issue "properly" without rewriting the includes in the source files, which might be of interest to you.)

jmickelin added a commit to jmickelin/PrusaSlicer that referenced this issue Nov 21, 2024
This solves the build error with the missing `Eigen3::Eigen` build
target.

Partially fixes prusa3d#13608
jmickelin added a commit to jmickelin/PrusaSlicer that referenced this issue Nov 21, 2024
This solves the build error with missing headers.

Partially fixes prusa3d#13608.
jmickelin added a commit to jmickelin/PrusaSlicer that referenced this issue Nov 21, 2024
This solves the linker error about missing `boost::log` symbols.

Fixes prusa3d#13608.
gentoo-bot pushed a commit to gentoo/gentoo that referenced this issue Nov 21, 2024
improved handling of eigen3
(thanks to jmickelin: prusa3d/PrusaSlicer#13608)
fixed libsoup double linking
(thanks to Alexander Golubev <fatzer2@gmail.com>)

Closes: #39379
Closes: https://bugs.gentoo.org/940182
Signed-off-by: Miroslav Šulc <fordfrog@gentoo.org>
@fordfrog
Copy link

@jmickelin thanks. i updated our ebuild with your eigen3 approach and it works for us too.

cfuga pushed a commit to cfuga/gentoo that referenced this issue Nov 21, 2024
improved handling of eigen3
(thanks to jmickelin: prusa3d/PrusaSlicer#13608)
fixed libsoup double linking
(thanks to Alexander Golubev <fatzer2@gmail.com>)

Closes: gentoo#39379
Closes: https://bugs.gentoo.org/940182
Signed-off-by: Miroslav Šulc <fordfrog@gentoo.org>
@renatoaguiar
Copy link

@jmickelin thanks for all that detailed information. Some of those errors were also affecting OpenBSD and now I can finally get a working build :)

@Jan-Soustruznik Jan-Soustruznik added the Build Build issues label Nov 22, 2024
lukasmatena pushed a commit that referenced this issue Dec 13, 2024
This solves the linker error about missing `boost::log` symbols.

Fixes #13608.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Build issues
Projects
None yet
Development

No branches or pull requests

4 participants