Remove link-time optimisation (LTO). - On GCC 4.9+ although GCC supports LTO, it requires use of the non-default gcc-ar & gcc-ranlib. Whilst we can ensure Ceres is compiled with these, doing so with GCC 4.9 causes multiple definition linker errors of static ints inside Eigen when compiling the tests and examples when they are not also built with LTO. - On OS X (Xcode 6 & 7) after the latest update to gtest, if LTO is used when compiling the tests (& examples), two tests fail due to typeinfo::operator== (things are fine if only Ceres itself is compiled with LTO). - This patch disables LTO for all compilers. It should be revisited when the performance is more stable across our supported compilers. Change-Id: I17b52957faefbdeff0aa40846dc9b342db1b02e3
diff --git a/docs/source/version_history.rst b/docs/source/version_history.rst index d1a1990..ee082c4 100644 --- a/docs/source/version_history.rst +++ b/docs/source/version_history.rst
@@ -27,6 +27,9 @@ Bug Fixes & Minor Changes ------------------------- +#. Remove use of link-time optimisation (LTO) for all compilers due to + portability issues with gtest / type_info::operator== & Eigen with + Clang on OS X vs GCC 4.9+ on Linux requiring contradictory 'fixes'. #. Use link-time optimisation (LTO) only when compiling Ceres itself, not tests or examples, to bypass gtest / type_info::operator== issue. #. Use old minimum iOS version flags on Xcode < 7.0.
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index cc2cb89..3a51309 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt
@@ -201,23 +201,6 @@ endif() endif() -# Use of -flto requires use of gold linker & LLVM-gold plugin, which might -# well not be present / in use and without which files will compile, but -# not link ('file not recognized') so explicitly check for support. -# -# Only use link-time optimisation (LTO) flags when building Ceres itself, as it -# causes an issue with type_info::operator==() in gtest's -# CheckedDowncastToActualType() in levenberg_marquardt_strategy_test & -# gradient_checking_cost_function_test if enabled for the tests as well. -include(CheckCXXCompilerFlag) -check_cxx_compiler_flag("-flto" HAVE_LTO_SUPPORT) -if (HAVE_LTO_SUPPORT) - message(STATUS "Enabling link-time optimization (-flto)") - append_target_property(ceres COMPILE_FLAGS "-flto") -else () - message(STATUS "Compiler/linker does not support link-time optimization (-flto).") -endif (HAVE_LTO_SUPPORT) - if (CMAKE_VERSION VERSION_LESS "2.8.12") # CMake version < 2.8.12 does not support target_compile_options(), warn # user that they will have to add compile flags to their own projects