问题
I want to use intel mkl in some optimazation problems, so I use intel example to test it. test.cpp:
#include <mkl.h>
#include <stdio.h>
typedef struct {
double re;
double im;
} complex16;
extern "C" void cblas_zdotc_sub(int, const void*, int, const void*, int, void*);
#define N 5
int main()
{
int n, inca = 1, incb = 1, i;
complex16 a[N], b[N], c;
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;
}
cblas_zdotc_sub(n, (void*)a, inca, (void*)b, incb, (void *)&c);
printf("The complex dot product is: ( %6.2f, %6.2f) ", c.re, c.im);
return 0;
}
when I compile it with "g++ -I/home/l/intel/mkl/include -w test.cpp - L"/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64" "/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64"/libmkl_intel_lp64.a -Wl,--start-group "/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64"/libmkl_intel_thread.a "/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64"/libmkl_core.a -Wl,--end-group -L"/home/l/intel/composer_xe_2011_sp1.6.233/mkl/../compiler/lib/intel64" -liomp5 -lpthread -lm -L/home/l/intel/mkl/lib/intel64 -o template", every thing is fine...
But if I separate the compile step and the link step, it gave me a link error:
test.cpp:(.text+0x10b): undefined reference to `cblas_zdotc_sub'
The commands I used to compile and link are:
compile:
g++ -I/home/l/intel/mkl/include -w -c test.cpp -o test.o
link:
g++ -I/home/l/intel/mkl/include -w -L"/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64" "/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64"/libmkl_intel_lp64.a -Wl,--start-group "/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64"/libmkl_intel_thread.a "/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64"/libmkl_core.a -Wl,--end-group -L"/home/l/intel/composer_xe_2011_sp1.6.233/mkl/../compiler/lib/intel64" -liomp5 -lpthread -lm ./test.o -L/home/l/intel/mkl/lib/intel64 -o template
I'm using ubuntu 12.04, gcc 4.6.3, intel composer_xe_2011_sp1.6.233.
回答1:
g++ ... "/home/l/intel/composer_xe_2011_sp1.6.233/mkl/lib/intel64"/libmkl_intel_lp64.a ... -liomp5 -lpthread -lm ./test.o ...
This command line is incorrect. The order of objects and libraries on the link line matters, and you've got it exactly opposite of what it should be. Move test.o
before the libraries, and it will just work (TM).
来源:https://stackoverflow.com/questions/11789695/strange-linking-error-with-intel-mkl-using-gcc-under-ubuntu