gpt4 book ai didi

c++ - 编译期间无法从 Accelerate Framework 链接 BLAS -OS Yosemite 10.0.5

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:16:09 26 4
gpt4 key购买 nike

我为赋值创建了一个矩阵多重性代码,但无法使该函数正常工作,所以我怀疑是 BLAS 库未正确链接。在 OS X 中,BLAS 已内置到 Accelerate Framework 中,因此在 makefile 中我通过 -framework Accelerate 链接了库。在 cpp 中,我还包含 #include<Accelerate/Accelerate.h> 的标题

在编译过程中,我的错误是:

Undefined symbols for architecture x86_64:
"dgemm_(char*, char*, int*, int*, int*, double*, double*, int*, double*, int*, double*, double*, int*)"

所以我创建了一个简单的测试代码,但在编译过程中仍然出现错误:

test_2.cpp:35:3: error: use of undeclared identifier 'dgemm_'
dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, ...
^
1 error generated.

我的简单测试代码是用

编译的
 clang++  -o test_2.exe test_2.cpp -framework Accelerate

我的简单代码是:

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cfloat>
#include <cmath>
#include <sys/time.h>
#ifdef __APPLE__
#include <Accelerate/Accelerate.h>
#else
#include <cblas.h>
#endif

using namespace std;
int main( int argc, char **argv )
{
int n=10;
int N=n;
double *A = (double*) malloc( n * n * sizeof(double) );
double *B = (double*) malloc( n * n * sizeof(double) );
double *C = (double*) malloc( n * n * sizeof(double) );
char TRANSA = 'N';
char TRANSB = 'N';
int M = N;
int K = N;
double ALPHA = 1.;
double BETA = 0.;
int LDA = N;
int LDB = N;
int LDC = N;
dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);
return 0;
}

最佳答案

根据 the documentation , Accelerate.framework 为所有 BLAS 函数添加前缀 cblas_。例如,dgemm 函数声明为

 void cblas_dgemm ( const enum CBLAS_ORDER __ Order , const enum CBLAS_TRANSPOSE __ TransA , const enum CBLAS_TRANSPOSE __ TransB , const int __ M , const int __ N , const int __ K , const double __ alpha , const double *__ A , const int __ lda , const double *__ B , const int __ ldb , const double __ beta , double *__ C , const int __ ldc ); 

关于c++ - 编译期间无法从 Accelerate Framework 链接 BLAS -OS Yosemite 10.0.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33341127/

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