13

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.

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

3 Answers 3

18

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";
1
  • I have found the need for -lm elsewhere already, but at least in my case the additional -ldl was what finally made it work. Cudos for documenting it here!
    – Raven
    Oct 14, 2022 at 13:43
9

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

1
  • 7
    Can you show the addition in detail? Thank you
    – Lucio
    May 12, 2015 at 1:51
6

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})

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .