gpt4 book ai didi

c++ - ATLAS gemm 将 undefined reference 链接到 'cblas_sgemm'

转载 作者:可可西里 更新时间:2023-11-01 16:33:16 25 4
gpt4 key购买 nike

这是我第一次尝试使用 ATLAS。我无法正确链接它。这是一个非常简单的 sgemm 程序:

...
#include <cblas.h>


const int M=10;
const int N=8;
const int K=5;

int main()
{
float *A = new float[M*K];
float *B = new float[K*N];
float *C = new float[M*N];

// Initialize A and B

cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, M, N, K, 1.0, A, K, B, N, 0.0, C, N);

...
}

当我在带有标准 ATLAS 安装的 linux 平台上编译它时,出现链接错误:

g++ test.c -lblas -lcblas -latlas -llapack
/tmp/cc1Gu7sr.o: In function `main':
test.c:(.text+0x29e): undefined reference to `cblas_sgemm(CBLAS_ORDER, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, int, int, int, float, float const*, int, float const*, int, float, float*, int)'
collect2: ld returned 1 exit status

如您所见,我尝试提供不同的库组合但没有帮助。我做错了什么?

最佳答案

你需要

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

因为你用 g++ 编译。

或者你甚至可以做

#ifdef __cplusplus
extern "C"
{
#endif
#include <cblas.h>
#ifdef __cplusplus
}
#endif

也能够编译为 C。

当您在 C++ 中编译时,名称会被破坏。但是由于 cblas 是用 C 语言编译的,所以导出的符号没有错位的名称。所以你必须指示编译器寻找 C 风格的符号。

关于c++ - ATLAS gemm 将 undefined reference 链接到 'cblas_sgemm',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10786237/

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