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

Problems with Static Linking with MKL

zeev_B_
Beginner
1,019 Views
Hello, We need your assistance with using the MKL library. We are using the following configuration: OS – Ubuntu 12.04 LTS 32 bit. SDK – Eclipse 3.7.2. Compiler - Intel IA-32 C++ Compiler (v13.0.0), using composer_xe_2013.1.117. We are trying to run the following code: int main() { double a[100], yr[100], yi[100[ ; int n = 100; vdSinCos(n,a,yi,yr); double p1r[10], p2r[20], resultrr[30]; int n1 = 10, n2 = 20, start = 0, stride = 1; vSLConvTaskPtr m_task; vsldConvNewTask1D(&m_task, VSL_CONV_MODE_AUTO, n1, n2, n1); vslConvSetStart(m_task, &start); vsldConvExec(m_task, &p1r[0], &stride, &p2r[0], &stride, &resultrr[0], &stride); vslConvDeleteTask(&m_task); } When we define dynamic linking to the MKL library the compilation and linking phase are completed with success and we can run the program. Our problem starts when we are trying to link the MKL statically. From our knowledge, when using the –mkl flag the static linking should work without and further requirement of us to specify any additional libraries of the MKL that should be linked since using the –mkl flag should enable all the library functionality. But still, we are getting the following errors during the linking phase: Building target: TestMath Invoking: Intel IA-32 C++ Linker icpc -static -L/opt/intel/composer_xe_2013.1.117/mkl/lib/ia32 -mkl=sequential -o "TestMath" ./src/TestMath.o /. src/TestMath.o: In function `main ' : / home/user/workspace/TestMath/Debug/../src/TestMath.cpp:17: undefined reference to `vdSinCos ' / home/user/workspace/TestMath/Debug/../src/TestMath.cpp:23: undefined reference to `vsldConvNewTask1D ' / home/user/workspace/TestMath/Debug/../src/TestMath.cpp:24: undefined reference to `vslConvSetStart ' / home/user/workspace/TestMath/Debug/../src/TestMath.cpp:25: undefined reference to `vsldConvExec ' / home/user/workspace/TestMath/Debug/../src/TestMath.cpp:26: undefined reference to `vslConvDeleteTask ' We have tried to manually link specific libraries in order to overcome this linking issue and only after we have specifically linked the mkl_intel, mkl_core and mkl_sequential libraries the project linking phase completes without any error, with the exception of the vsIdConvExec function, so we have commented. make -k all Building file: ../src/TestMath.cpp Invoking: Intel IA-32 C++ Compiler icpc -g -mkl=sequential -I/opt/intel/composer_xe_2013.1.117/mkl/include -MMD -MP -MF"src/TestMath.d" - MT"src/TestMath.d" -c -o "src/TestMath.o" "../src/TestMath.cpp" Finished building: ../src/TestMath.cpp Building target: TestMath Invoking: Intel IA-32 C++ Linker icpc -static -L/opt/intel/composer_xe_2013.1.117/mkl/lib/ia32 -mkl=sequential -o "TestMath" ./src/TestMath.o -lmkl_intel -lmkl_core -lmkl_sequential Finished building target: TestMath When we have tryied to uncomment the call to the vsIdConvExec function we got enormous number of undefined reference errors. Even when we`ve tried to statically link all the .a libraries in the ia32 folder we still got the undefined reference erros. Please advise how to configure correctly our static linking (shouldn’t –mkl be enough?) since dynamic linking is not possible in order environment. Thanks.
0 Kudos
4 Replies
mecej4
Honored Contributor III
1,019 Views

When you use static linking, and you list one or more .o objects after one or more static libraries that contain symbols needed by the object(s), the linking will fail. See, for example, the explanation in http://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking/ . 

The solution is quite simple: list the names of the .o files to be linked before the list of libraries in the command that invokes the linker ld. In your makefile, you should have something similar to:

[bash]

icpc -static ./src/TestMath.o -L/opt/intel/composer_xe_2013.1.117/mkl/lib/ia32 -mkl=sequential -o "TestMath"

[/bash]

0 Kudos
TimP
Honored Contributor III
1,019 Views

static linking of MKL has the additional problem of circular dependencies which has to be resolved by --start-group .....   --end-group linker directives, and full path names of the libraries, as shown in the MKL link advisor  http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor

-mkl=sequential is a good idea for initial testing, but I think it may not work with -static.

0 Kudos
Ying_H_Intel
Employee
1,019 Views

Hello, 

As mecej4 and Tim pointed out,  one key is  the order of linked library,  another key is the -mkl and -static combination.  Here is one KB talking about the problem:  

http://software.intel.com/en-us/articles/link-error-when-static-linking-to-intel-mkl-on-linux-6

So the recommend static link line is 

icpc -intel-static ./src/TestMath.o -L/opt/intel/composer_xe_2013.1.117/mkl/lib/ia32 -mkl=sequential -o TestMath

Best Regards,

Ying 

 

 

 

 

0 Kudos
miro_ilias
Beginner
1,019 Views

Hi,

this simple Fortran90 program does not link statically with --mkl=sequential/parallel:

milias@login.grid.umb.sk:~/Work/qch/software/software_projects/autocmake_devel/autocmake_miroi/test/fc_blas/build_ifort_mklpar_static/./mnt/apps/intel/composer_xe_2013_sp1.1.106/bin/intel64/ifort   -static-intel  -mkl=sequential    -O3 src/CMakeFiles/example.dir/example.f90.o  -o bin/example
src/CMakeFiles/example.dir/example.f90.o: In function `MAIN__':
/home/milias/Work/qch/software/software_projects/autocmake_devel/autocmake_miroi/test/fc_blas/src/example.f90:(.text+0x37a): undefined reference to `dgemm_'
milias@login.grid.umb.sk:~/Work/qch/software/software_projects/autocmake_devel/autocmake_miroi/test/fc_blas/build_ifort_mklpar_static/.
milias@login.grid.umb.sk:~/Work/qch/software/software_projects/autocmake_devel/autocmake_miroi/test/fc_blas/build_ifort_mklpar_static/./mnt/apps/intel/composer_xe_2013_sp1.1.106/bin/intel64/ifort   -static-intel  -mkl=parallel    -O3 src/CMakeFiles/example.dir/example.f90.o  -o bin/example
src/CMakeFiles/example.dir/example.f90.o: In function `MAIN__':
/home/milias/Work/qch/software/software_projects/autocmake_devel/autocmake_miroi/test/fc_blas/src/example.f90:(.text+0x37a): undefined reference to `dgemm_'

Without -static-intel flag it works:

milias@login.grid.umb.sk:~/Work/qch/software/software_projects/autocmake_devel/autocmake_miroi/test/fc_blas/build_ifort_mklpar_static/./mnt/apps/intel/composer_xe_2013_sp1.1.106/bin/intel64/ifort    -mkl=parallel    -O3 src/CMakeFiles/example.dir/example.f90.o  -o bin/example
milias@login.grid.umb.sk:~/Work/qch/software/software_projects/autocmake_devel/autocmake_miroi/test/fc_blas/build_ifort_mklpar_static/.bin/example
 PASSED

Any help ? I guess --mkl=<sequential/parallel/cluster> is intended with dynamical linking only. Comments please ?

0 Kudos
Reply