【问题标题】:Undefined reference: Cblas not linking未定义的参考:Cblas 未链接
【发布时间】:2016-01-29 21:59:26
【问题描述】:

我在链接一个简单的 cblas 程序时遇到问题,这是我的最小示例:

extern "C"
{    
    #include <cblas.h> 
}
#include <iostream>

int main() {

    int lda = 3;

    float A[] = { 0.11, 0.12, 0.13,
                  0.21, 0.22, 0.23 };

    int ldb = 2; 

    float B[] = { 1011, 1012,
                  1021, 1022,
                  1031, 1032 };

    int ldc = 2;

    float C[] = { 0.00, 0.00,
                  0.00, 0.00 };

    cblas_sgemm(CblasRowMajor,
                CblasNoTrans,
                CblasNoTrans,
                2, 2, 3, 1.0, A, lda, B, ldb, 0.0, C, ldc);

    std::cout << "[ " << C[0] << ", " << C[1] << "\n " << C[2] 
              << ", " << C[3] << " ]\n";
}

现在我正在尝试用g++ -lcblas test.cpp 编译程序,但这给了我

gdev-home@gdev-home:~/Documents$ g++ -lcblas test.cpp
/tmp/ccEwRr40.o: In function `main':
test.cpp:(.text+0x112): undefined reference to `cblas_sgemm'
collect2: error: ld returned 1 exit status

这意味着它没有正确链接。奇怪的是我确实有 cblas 库,我通过 atlas 安装了它们

gdev-home@gdev-home:~/Documents$ dpkg --get-selections | grep atlas
libatlas-base-dev               install
libatlas-dev                    install
libatlas3-base                  install

如果你看里面/usr/lib我有

gdev-home@gdev-home:/usr/lib$ ls | grep blas
libblas
libblas.a
libblas.so
libblas.so.3
libblas.so.3gf
libcblas.a
libcblas.so
libcblas.so.3
libcblas.so.3gf
libf77blas.a
libf77blas.so
libf77blas.so.3
libf77blas.so.3gf

有谁知道为什么这个程序链接失败?

【问题讨论】:

    标签: c++ ld blas cblas


    【解决方案1】:

    我认为 -lcblas 参数应该在 test.cpp 之后。

    【讨论】:

      猜你喜欢
      • 2019-07-24
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多