Ubuntu – undefined reference to symbol ‘exp@@GLIBC_2.2.5’

cmakecompilingldmake

Similar question has been asked here but is unanswered.

I have an implementation of Levenberg-Marquardt (downloaded from somewhere) and I'm trying to compile it but getting the following error.

gauravloj@vertex:~/Documents/source_code/non-rigid_registration/Gauss_newton/levmar-2.6$ make
[ 87%] Built target levmar
Linking C executable lmdemo
/usr/bin/ld: CMakeFiles/lmdemo.dir/lmdemo.c.o: undefined reference to symbol 'exp@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [lmdemo] Error 1
make[1]: *** [CMakeFiles/lmdemo.dir/all] Error 2
make: *** [all] Error 2

At many sites, the solution given was to add some flags (e.g here and here). But none of them worked for me.

Here is the Makefile, here is the CMakeLists.txt and here is the CMakeCache.txt.

Best Answer

Seems like the user who found the solution never shared it later. For guys who are trying to find the solution just add the math library explicitly and also add -ldl

So -lm and -ldl in the gcc line you are compiling and it should go just fine.

Alternatively, in most cases you can also explicitly define CFLAGS and alleviate the issue that way. These are just two ways of solving,

Example:

user@compiler-shell$ EXPORT CFLAGS=" -g -O2 -lm -ldl -Wall -Wpointer-arith -finline-functions -ffast-math -funroll-all-loops";