sofa icon indicating copy to clipboard operation
sofa copied to clipboard

Linker Error while compiling SOFA with LLVM 16

Open sandeep-amd opened this issue 2 years ago • 2 comments

Hi,

While trying to compile SOFA(https://github.com/sofa-framework/sofa => branch "v23.06") with LLVM 16 , we are getting linker errors as below,

ld.lld: error: undefined symbol: vtable for sofa::linearalgebra::FullVector

referenced by ld-temp.o lto.tmp:(sofa::component::odesolver::testing::getVector(boost::intrusive_ptrsofa::simulation::Node, sofa::core::TVecId<(sofa::core:: VecType)0, (sofa::core::VecAccess)0>, bool)) did you mean: typeinfo for sofa::linearalgebra::FullVector defined in: ../../../../../lib/libSofa.LinearAlgebra.so.23.06.00 the vtable symbol may be undefined because the class is missing its key function (see https://lld.llvm.org/missingkeyfunction) clang-16: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [Sofa/Component/ODESolver/Backward/tests/CMakeFiles/Sofa.Component.ODESolver.Backward_test.dir/build.make:212: bin/Sofa.Component.ODESolver .Backward_test] Error 1 make[1]: *** [CMakeFiles/Makefile2:5981: Sofa/Component/ODESolver/Backward/tests/CMakeFiles/Sofa.Component.ODESolver.Backward_test.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs...

To Resolve this, we have included definition of key function of FullVector calss in FullVector.cpp. The key function seems to be resize() - i.e the first non-pure, non-linear and virtual function in a polymorphic class. The actual definition of resize() is present in FullVector.inl file and we have commented it out.

Please let us know if the changes are good.

Thanks, Sandeep.

sandeep-amd avatar Dec 21 '23 12:12 sandeep-amd

Hi,

thanks for reporting a build problem. I have not had the chance to play with LLVM 16 yet.

I agree that the key function of FullVector is resize. However, it is defined in the inl file. The template is explicitly instantiated in the cpp file, and it corresponds to the template parameter used in getVector (function from EigenTestUtilities.h). The cpp file includes the inl file. Therefore, I don't understand that the linker emit an error suggesting that it is not defined...

Was it the only problem in the whole build?

alxbilger avatar Dec 21 '23 14:12 alxbilger

Yes, that is the only problem we have encountered. Having the definition in the cpp file seems to fix the issue.

Also, it seems like without a key function definition in the cpp file for which obj needs to be created , there is no vtable reference.

sandeep-amd avatar Dec 21 '23 14:12 sandeep-amd