Tracy: gcc: undefined references with ScopedTimer in lambdas when linking [Ubuntu23.04]
Problem
Description Trying to build with SOFA_TRACY enabled on Ubuntu 23.04/gcc, got some errors when linking LinearSolver.Direct. No such error with MSVC2022.
Could be a bug from Tracy ? 🤔
Steps to reproduce Enable SOFA_TRACY and TRACY_ENABLE on Ubuntu23.04 and gcc,
Expected behavior Linking correctly 😅
Environment
Context
- System: Ubuntu 23.04, gcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~23.04)
- Version of SOFA: master (https://github.com/sofa-framework/sofa/commit/22d783bb366fae979b31df6b22de60dde5a19d76)
Logs
/usr/bin/ld: Sofa/Component/LinearSolver/Direct/CMakeFiles/Sofa.Component.LinearSolver.Direct.dir/src/sofa/component/linearsolver/direct/SparseLDLSolver.cpp.o:(.data.rel.ro.local._ZZZN4sofa9component12linearsolver6direct15SparseLDLSolverINS_13linearalgebra35CompressedRowSparseMatrixMechanicalINS_4type3MatILj3ELj3EdEENS4_19CRSMechanicalPolicyEEENS4_10FullVectorIdEENS1_15NoThreadManagerEE17doAddJMInvJtLocalEPNS4_10BaseMatrixEPKNS4_12SparseMatrixIdEEdPNS2_23SparseLDLImplInvertDataINS6_6vectorIiNS6_16CPUMemoryManagerIiEEEENSM_IdNSN_IdEEEEEEENKUlRKT_E_clINS_10simulation5RangeIjEEEEDaSW_E26__tracy_source_location204[_ZZZN4sofa9component12linearsolver6direct15SparseLDLSolverINS_13linearalgebra35CompressedRowSparseMatrixMechanicalINS_4type3MatILj3ELj3EdEENS4_19CRSMechanicalPolicyEEENS4_10FullVectorIdEENS1_15NoThreadManagerEE17doAddJMInvJtLocalEPNS4_10BaseMatrixEPKNS4_12SparseMatrixIdEEdPNS2_23SparseLDLImplInvertDataINS6_6vectorIiNS6_16CPUMemoryManagerIiEEEENSM_IdNSN_IdEEEEEEENKUlRKT_E_clINS_10simulation5RangeIjEEEEDaSW_E26__tracy_source_location204]+0x8): undefined reference to `sofa::component::linearsolver::direct::SparseLDLSolver<sofa::linearalgebra::CompressedRowSparseMatrixMechanical<sofa::type::Mat<3u, 3u, double>, sofa::linearalgebra::CRSMechanicalPolicy>, sofa::linearalgebra::FullVector<double>, sofa::component::linearsolver::NoThreadManager>::doAddJMInvJtLocal(sofa::linearalgebra::BaseMatrix*, sofa::linearalgebra::SparseMatrix<double> const*, double, sofa::component::linearsolver::direct::SparseLDLImplInvertData<sofa::type::vector<int, sofa::type::CPUMemoryManager<int> >, sofa::type::vector<double, sofa::type::CPUMemoryManager<double> > >*)::{lambda(auto:1 const&)#1}::operator()<sofa::simulation::Range<unsigned int> >(sofa::simulation::Range<unsigned int> const&) const::__FUNCTION__'
and so on.
Workaround
In Sofa/Component/LinearSolver/Direct/src/sofa/component/linearsolver/direct/SparseLDLSolver.inl, function doAddJMInvJtLocal().
Commenting the SCOPED_TIMER lines from inside the lambdas allows the linking to finish successfully.
Apparently, a bug with gcc12 and/or Ubuntu 23.04, just upgraded to Ubuntu 23.10 (with gcc13.2) and it works well 😅
To avoid this situation, we can convert this lambda to a method. Let's keep this issue open. I'll add the flag good first issue.