3

I am trying to compile an example program from the Intel MKL library (/opt/intel/mkl/examples/versionqueryc/). I copied the source code (C-file) to a new directory. I then went and tried to build this example using CMake.

In the course of debugging this, I am stuck when trying to use the following command (isolated from cmake by now).

It doesn't find the Math library but I have -lm included in the linking. So what is going on?

:~/devel/mkl/MKL Test/build$  /usr/bin/gcc -m64 CMakeFiles/mkltest.dir/main.c.o \
>     -o mkltest    -rdynamic -L/home/myuser/src/intel/mkl/lib/intel64 \
>     -lm  -lmkl_intel_lp64 -lmkl_sequential -lmkl_core  -lmkl_cdft_core \
>     -lmkl_scalapack_lp64 \
>     /home/myuser/src/intel/lib/intel64/libiomp5.so \
>     -Wl,-rpath,/home/myuser/src/intel/mkl/lib/intel64:/home/myuser/src/intel/lib/intel64 
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `logf'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `atan2'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `sin'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `fabs'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `exp'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `sqrtf'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `cos'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `sqrt'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_sequential.so: undefined reference to `log'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `pow'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `log10'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `ceil'
/home/myuser/src/intel/mkl/lib/intel64/libmkl_core.so: undefined reference to `expf'
collect2: ld returned 1 exit status
Unapiedra
  • 15,037
  • 12
  • 64
  • 93
  • I'm sure this is a duplicate, but I'm too lazy to track it down. – Keith Thompson May 20 '14 at 16:14
  • 1
    http://stackoverflow.com/questions/11789695/strange-linking-error-with-intel-mkl-using-gcc-under-ubuntu?rq=1 (Order matters, but not specific to inter-libraries); http://stackoverflow.com/a/19696864/461597 (Mentions this as inter-library-dependency). – Unapiedra May 20 '14 at 16:18

1 Answers1

9

Put -lm as the last parameter, the order of parameters is important while linking.

ismail
  • 46,010
  • 9
  • 86
  • 95
  • 1
    Thanks. Further explanation here: http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html – Unapiedra May 20 '14 at 16:08
  • Another reference: http://fedoraproject.org/wiki/UnderstandingDSOLinkChange Strict DSO linking sequence introduced in `gcc-4.4.3-5`. – Kamiccolo May 20 '14 at 16:12