sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
917 stars 310 forks source link

Tracy: gcc: undefined references with ScopedTimer in lambdas when linking [Ubuntu23.04] #4283

Open fredroy opened 11 months ago

fredroy commented 11 months ago

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

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.

fredroy commented 11 months ago

Apparently, a bug with gcc12 and/or Ubuntu 23.04, just upgraded to Ubuntu 23.10 (with gcc13.2) and it works well 😅

alxbilger commented 11 months ago

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.