4

boost version 1.64
gcc version 6.4.1
Linux OpenSuse x64 42.2
Cmake 3.5.2

[linking, no LTO] works:

-std=gnu++11 -O2  -fopenmp -static /opt/lib64/libboost_filesystem.a /opt/lib64/libboost_system.a

[linking, with LTO] does not work:

-std=gnu++11 -O2  -fopenmp -flto=8 -static /opt/lib64/libboost_filesystem.a /opt/lib64/libboost_system.a

error:

/opt/lib64/libboost_filesystem.a(operations.o): In function `boost::filesystem::detail::is_empty(boost::filesystem::path const&, boost::system::error_code*)':
operations.cpp:(.text+0x536a): undefined reference to `vtable for boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>'
/opt/lib64/libboost_filesystem.a(operations.o): In function `(anonymous namespace)::remove_all_aux(boost::filesystem::path const&, boost::filesystem::file_type, boost::system::error_code*)':
operations.cpp:(.text+0x699d): undefined reference to `vtable for boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>'
operations.cpp:(.text+0x6add): undefined reference to `vtable for boost::detail::sp_counted_impl_p<boost::filesystem::detail::dir_itr_imp>'
collect2: error: ld returned 1 exit status
CMakeFiles/zebr.dir/build.make:137: recipe for target 'zebr' failed

--> boost libraries compiled with gcc 6.4.1 and -std=gnu++11 flag
--> with gcc 4.8.5 everything works fine

Mettbe
  • 101
  • 1
  • 6
  • Same here with gcc 7.3.0 and boost 1.66.0. Did you find a workaround? – Mika Fischer Apr 18 '18 at 08:44
  • Possible duplicate: https://stackoverflow.com/q/40350936/8360627 – John Ilacqua Mar 06 '20 at 00:04
  • I had a similar issue and ended up only enabling LTO for gcc 8+. Another possible workaround is to add `-fno-devirtualize`, but I'm not sure being able to enable LTO is worth disabling devirtualization. – John Ilacqua Mar 06 '20 at 00:06
  • Is your Boost compiled with LTO? Also, static libraries (like `/opt/lib64/libboost_filesystem.a`) need gcc-ar when LTO is used. – Petross404 May 01 '22 at 08:45

0 Answers0