Operating System: Ubuntu 12.04, Ubuntu 13.10
Problem Description: Build Intel® Math kernel Library (Intel® MKL) application on Ubuntu OS, get the following error while execution.
symbol lookup error: /opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_lp64.so: undefined symbol: mkl_vsl_serv_threader_for
This occurs on Ubuntu 12.04 system with GCC 4.6.3. The same program can be compiled with Intel® C/C++ Compiler (icc) and run without any problems on the same system. The same program can be run without the above error on another machine with Ubuntu 13.04 and gcc 4.7.3.
All of the environment variables have been correctly set and the link line is from MKL Linker Advisor.
$source /opt/intel/composer_xe_2013_sp1.1.106/mkl/bin/mklvars.sh intel64
$gcc -DMKL_ILP64 -fopenmp -m64 -I$MKLROOT/include lapacke_dgelsd_row.c -L$MKLROOT/lib/intel64 -lmkl_intel_ilp64 -lmkl_core -lmkl_sequential -lpthread -lm
$./a.out
Example:
There are several users who reported this issue in MKL forum
1. http://software.intel.com/en-us/forums/topic/499216
Ubuntu 12.04.3 + gcc 4.6.3 shows error, but with icc or Ubuntu 13.04 + gcc 4.7.3 is ok.
2. http://software.intel.com/en-us/forums/topic/499180
Ubuntu 12.04 +gcc 4.8 is ok, but Ubuntu 13.10 have issue:
/opt/intel/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_ok_to_fork
Juan Jose Garcia Ripoll provided a build log file by
g++ -v -m64 -L/opt/intel/composerxe/lib/intel64/ -I/opt/intel/mkl/include -I/home/…/include -g -O2 -O2 -o exp_1.exe exp_1.cc … -L/opt/intel/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -ldl -lpthread -Wl,--verbose
3. http://software.intel.com/en-us/forums/topic/351714
abhishek s provided test case and compared ldd result.
Andrey Tikhonov provided two workarounds:
Set environment variable LD_PRELOAD=/path/to/libmkl_core.so:/path/to/libmkl_intel_thread.so Or force ld to link to this libraries by using --no-as-needed switch
Above discussions discovered the fact that the executable binary refers to only MKL interface library (libmkl_intel_ilp64.so or libmkl_intel_lp64.so), but ignores the dependent threading and core libraries (libmkl_intel_thread.so and libmkl-core.so).
Resolution Status:
We suspect some GCC versions on Ubuntu showed this observable --as-needed behavior as default for binary-startup-time optimization reasons.
The option suggests that linker do not add DT_NEEDED ELF flag for all specified libraries but only for libraries with symbols used in the source code. Thus relevant libraries like threading and core libraries are not loaded at runtime and executable fails with runtime error.
So as a temporary workaround, please add –no-as-needed explicitly in link line to force the linker to link all specified libraries. e.g.:
gcc -DMKL_ILP64 -fopenmp -m64 -I$MKLROOT/include lapacke_dgelsd_row.c -L$MKLROOT/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_core -lmkl_sequential -lpthread -lm