gpt4 book ai didi

c++ - undefined reference : Cblas not linking

转载 作者:行者123 更新时间:2023-11-28 00:10:27 25 4
gpt4 key购买 nike

我在链接一个简单的 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

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

最佳答案

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

关于c++ - undefined reference : Cblas not linking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33419678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com