9

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.

  • What is your glibc version? – nixeagle Sep 23 '14 at 22:49
  • ldd --version gave (Ubuntu EGLIBC 2.19-0ubuntu6.3) 2.19. – Shashwat Sep 24 '14 at 10:53
  • Please include your Makefile. This is clearly something with broken library dependencies (and possible glib version mismatches). – nixeagle Sep 24 '14 at 14:42
  • 2
    Are you sure you've tried adding -lm? Where did you add it? – muru Sep 25 '14 at 3:09
  • @Shashwat: Where exactly did you add this? Can you please post the code? Thanks – user380373 Feb 19 '15 at 10:44
6

I've added -lm into CMakeLists.txt where libraries are being assigned. It's working now.

  • 3
    Can you show the addition in detail? Thank you – Lucio May 12 '15 at 1:51
6

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";
3

I found this thread with a similar problem. Explicitly, the solution is to find and change in your CMakeLists.txt file:

TARGET_LINK_LIBRARIES(lmdemo ${LIBS})

to

TARGET_LINK_LIBRARIES(lmdemo -lm ${LIBS})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.