奇怪的链接错误与Intel mkl在Ubuntu下使用gcc [英] Strange linking error with intel mkl using gcc under ubuntu

查看:451
本文介绍了奇怪的链接错误与Intel mkl在Ubuntu下使用gcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一些优化问题中使用intel mkl,所以我使用intel示例来测试它。
test.cpp:

  #include< mkl.h> 
#include< stdio.h>
typedef struct {
double re;
double im;
} complex16;

externCvoid 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 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(复杂点产品是:(%6.2f,%6.2f),c.re,c.im);
返回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):对`cblas_zdotc_sub'的未定义引用

我用来编译和链接的是:

编译:

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模板

我使用ubuntu 12.04,gcc 4.6.3, intel composer_xe_2011_sp1.6.233。

解决方案


g ++ .../ home / l / intel / composer_xe_2011_sp1 .6.233 / mkl / lib / intel64/libmkl_intel_lp64.a ... -liomp5 -lpthread -lm ./test.o ...


这个命令行不正确。链接行上的对象和库的顺序很重要,并且您准确无误与它应该是相反的。在库之前移动 test.o ,它就会正常工作(TM)。


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.

解决方案

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).

这篇关于奇怪的链接错误与Intel mkl在Ubuntu下使用gcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆