Fix ODR violations

Compiling Ceres with Schur specializations and Link Time Optimization
(LTO) results in warnings such as

    /usr/include/eigen3/Eigen/src/Core/ProductEvaluators.h:31:8: warning: type ‘struct evaluator’ violates the C++ One Definition Rule [-Wodr]
       31 | struct evaluator<Product<Lhs, Rhs, Options>> : public product_evaluator<Product<Lhs, Rhs, Options>> {
          |        ^

due to the redefinition of EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD which
alters internal Eigen class definitions and consequently results in ODR
violations.

Avoid the ODR violation by renaming the Eigen namespace in translation
units that redefine EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD.

While the issue is diagnosed in LTO builds of Ceres only, the problem
exists in non-LTO builds as well and per standard the compiler is not
even required to diagnose ODR issues. ODR violations constitute
undefined behavior.

Change-Id: Idf7c7a30cc8d3a86b0d62cbd33bef58783a62ee4
This commit is contained in:
Sergiu Deitsch
2025-09-28 08:55:53 +02:00
parent de96ed58f5
commit a2bab5af51
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ jobs:
- name: Setup Build Environment
if: matrix.build_type == 'Release'
run: |
echo 'CXXFLAGS=-flto=auto' >> $GITHUB_ENV
echo 'CXXFLAGS=-flto=auto -Werror=odr' >> $GITHUB_ENV
- name: Setup Runtime Environment
run: |