Symbol Lookup Error When Linking Intel® MKL with GCC on Ubuntu

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/ 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/ 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



There are several users who reported this issue in MKL forum


   Ubuntu 12.04.3 + gcc 4.6.3 shows error, but with icc or Ubuntu 13.04 + gcc 4.7.3 is ok.


Ubuntu 12.04 +gcc 4.8 is ok, but Ubuntu 13.10 have issue:

 /opt/intel/mkl/lib/intel64/ 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 … -L/opt/intel/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -ldl -lpthread -Wl,--verbose


abhishek s  provided test case and compared ldd result.

 Andrey Tikhonov  provided two workarounds:

Set environment variable LD_PRELOAD=/path/to/ Or force ld to link to this libraries by using --no-as-needed switch


I already tried the mkl line advisor, but I got
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/ undefined reference to `pthread_mutex_trylock'

Above discussions discovered the fact that the executable binary refers to only MKL interface library ( or, but ignores the dependent  threading and core libraries ( and

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 

Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.