我想在一些优化问题中使用 intel mkl,所以我使用 intel example 来测试它。测试.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;
}
当我用 "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 模板”,一切都很好...
但是如果我将编译步骤和链接步骤分开,它会给我一个链接错误:
test.cpp:(.text+0x10b): undefined reference to `cblas_zdotc_sub'
我用来编译和链接的命令是:
编译:
g++ -I/home/l/intel/mkl/include -w -c test.cpp -o test.o
关联:
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 模板
我正在使用 ubuntu 12.04、gcc 4.6.3、intel composer_xe_2011_sp1.6.233。