Search code examples
dynamic-linkingiccintel-mkl

Facing linking trouble with mkl in linux Intel compiler (icc)


here is the command line in linux:

icc test.c -o test.o -L/opt/intel/current/mkl/intel64 -I/opt/intel/current/mkl/include -lmkl_intel_ilp64 -lmkl_core -lmkl_scalapack_ilp64

after running this command: I got a long line of undefined reference errors. I have also tried in eclipse but could not resolve the linking problem there too. I would be happy if anyone just help me to run a small code like this:

//test.c- a sample code from user guide
#include "mkl.h"
#define N 5
void main()
{
int n, inca = 1, incb = 1, i;
typedef struct{ double re; double im; } complex16;
complex16 a[N], b[N], c;
void zdotc();
n = N;
for( i = 0; i < n; i++ ){
a[i].re = (double)i; a[i].im = (double)i * 2.0;
b[i].re = (double)(n - i); b[i].im = (double)i * 2.0;
}
zdotc( &c, &n, a, &inca, b, &incb );
printf( "The complex dot product is: ( %6.2f, %6.2f) ", c.re, c.im );
} 

my server

> MKLROOT: /opt/intel/current/mkl/
>           library: $MKLROOT/lib/intel64/
>           include:$MKLROOT/include

ICC 64bit is installed.

thanks in advance.


Solution

  • The best way to get right linkline for Intel MKL is using MKL Linkline Advisor. Even with right LD_LIBRARY_PATH compiler options and set of libraries you link doesn't look right. Should be

    -DMKL_ILP64 -I$(MKLROOT)/include -L$(MKLROOT)/lib/intel64 -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -openmp -lpthread -lm