Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Symbol Lookup Error After Linking MKL with GCC

Yong_Jae_K_
Beginner
1,946 Views

I am attempting to compile and link the following program with gcc.

 

 

0 Kudos
8 Replies
Yong_Jae_K_
Beginner
1,946 Views

The following is my intended post, but this website flagged it as spam incorrectly.

I am attempting to compile and link the following program with gcc that uses the function LAPACKE_dgelsd.

Assuming the aforementioned program is called dgelsd_example.c, I am able to successfully compile and link using icc with the following line. 

icc dgelsd_example.c -mkl

However, I am having difficulty compiling and linking the program with gcc. When I use the MKL Link Line Advisor, I come up with the following line.

  gcc -DMKL_ILP64 -fopenmp -m64 -I$MKLROOT/include dgelsd_example.c  -L$MKLROOT/lib/intel64 -lmkl_intel_ilp64 -lmkl_core -lmkl_sequential -lpthread -lm

But I receive the following error when I execute the executable.

symbol lookup error: /home/yongjae/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_lp64.so: undefined symbol: mkl_vsl_serv_threader_for

All of the environment variables have been correctly set. I am aware there are similar questions, but I did not find a definitive answer. How do I compile and link the program with gcc? 

0 Kudos
Ying_H_Intel
Employee
1,946 Views

Hi Yang Jae K. 

From the link link, there is -lmkl_intel_ilp64 (libmkl_intel_ilp64.so) ,  but in the executable, your mentioned, mkl_intel_lp64.so. Could you please check if it is typo error or other problem? 

On the other hand, could you run the dgelsd example ( examples/lapacke/source/ lapacke_dgelsd_row.c) under mkl example directory? 

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

LAPACKE_dgelsd (row-major, high-level) Example Program Results

 Minimum norm solution
  -0.69  -0.24   0.06
  -0.80  -0.08   0.21
   0.38   0.12  -0.65
   0.29  -0.24   0.42
   0.29   0.35  -0.30

 Effective rank =      4

Best Regards,

Ying 

 

 

0 Kudos
Yong_Jae_K_
Beginner
1,946 Views

I followed your suggestions and still receive errors. 

source intel/composer_xe_2013_sp1.1.106/mkl/bin/mklvars.sh intel64

gcc -DMKL_ILP64 -fopenmp -m64 -I$MKLROOT/include dgelsd_example.c  -L$MKLROOT/lib/intel64 -lmkl_intel_ilp64 -lmkl_core -lmkl_sequential -lpthread -lm

 ./a.out

However, I receive the following error. 

./a.out: symbol lookup error: /home/yongjae/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_ilp64.so: undefined symbol: mkl_vsl_serv_threader_for

I am running Ubuntu 12.04.3 and gcc 4.6.3. Please, advise. 

 

0 Kudos
Yong_Jae_K_
Beginner
1,946 Views

By the way, dgelsd_example.c is equivalent to lapacke_dgelsd_row.c. Please, advise. 

0 Kudos
Ying_H_Intel
Employee
1,946 Views

Hi Yong Jae K. 

could it  be some problem with the GCC on Ubuntu, Do you have other machine to try? 

I just try Ubuntu 13.04 and gcc version 4.7.3, the code run fine too. (in first reply, i try Redhat)  So the problem seems no related to OS. 

But as you know, from http://software.intel.com/en-us/forums/topic/351714

 ldd ./mklMatrixMul: 

linux-vdso.so.1 =>  (0x00007fffde182000)
    libmkl_intel_lp64.so => /opt/intel/composer_xe_2013_sp1.0.080/mkl/lib/intel64/libmkl_intel_lp64.so (0x00007fb5908e2000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb590507000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb590303000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fb591007000)

But with the "fine" exectuable,  it should be link 3 libraries.  The symbols mkl_vsl_serv  is defined in mkl_sequential.so. 

 ldd a.out
        linux-vdso.so.1 =>  (0x00007fffb2c81000)
        libmkl_intel_ilp64.so => /opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_ilp64.so (0x00007fbf7709c000)
        libmkl_core.so => /opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_core.so (0x00007fbf759dd000)
        libmkl_sequential.so => /opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_sequential.so
(0x00007fbf7531a000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00000038e1200000)
        libm.so.6 => /lib64/libm.so.6 (0x00000038e0600000)
        libgomp.so.1 => /usr/lib64/libgomp.so.1 (0x00000038e5a00000)
        libc.so.6 => /lib64/libc.so.6 (0x00000038e0a00000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00000038e0e00000)
        /lib64/ld-linux-x86-64.so.2 (0x00000038e0200000)
        librt.so.1 => /lib64/librt.so.1 (0x00000038e1a00000)

I'm not sure,  but you may try the command 

gcc -DMKL_ILP64 -fopenmp -m64 -I$MKLROOT/include dgelsd_example.c  -L$MKLROOT/lib/intel64 -Wl, --start-group  -lmkl_intel_ilp64 -lmkl_core -lmkl_sequential -Wl,--end-group  -lpthread -lm

or use static link 

 -Wl,--start-group $(MKLROOT)/lib/intel64/libmkl_intel_ilp64.a $(MKLROOT)/lib/intel64/libmkl_core.a $(MKLROOT)/lib/intel64/libmkl_sequential.a -Wl,--end-group -lpthread -lm

Best Regards,
Ying 

0 Kudos
Yong_Jae_K_
Beginner
1,946 Views

I executed the aforementioned commands with gcc-4.8, and I still receive the same error. What is going on? 

0 Kudos
Ying_H_Intel
Employee
1,946 Views

Hello Yong Jae K. 

We discussed the issue with our developing experts.  Based on the fact of the binary refers to only MKL interface library ( libmkl_intel_lp64.so) which have symbols used in your code, but ignore the core and sequential libraries. We guess some GCC version deployed --as-needed as default behaviors.  ( This option tells linker do not add DT_NEEDED ELF flag for all specified libraries but only for libraries with symbols used in the code, thus dependency/correlated library are not loaded at runtime and executable faile with runtime error). 

So the solution is to change the behaviors, for example, add link option -Wl, --no-as-needed. It guarantee all specified libraries will be written as required at runtime.

The link line like 

gcc -DMKL_ILP64 -fopenmp -m64 -I$MKLROOT/include dgelsd_example.c  -L$MKLROOT/lib/intel64 -Wl, --no-as-needed  -lmkl_intel_ilp64 -lmkl_core -lmkl_sequential  -lpthread -lm

Could you please try it and let us know if it works?

Best Regards,
Ying 

 

0 Kudos
Yong_Jae_K_
Beginner
1,946 Views

Yes, that worked. Thank you. I appreciate your help. 

 

0 Kudos
Reply