编译期间无法从Accelerate Framework中链接BLAS -OS Yosemite 10.0.5 [英] Cannot link the BLAS from Accelerate Framework during compilation -OS Yosemite 10.0.5
问题描述
我为分配创建了矩阵多重性代码,但无法使函数正常工作,因此我怀疑这是BLAS库未正确链接.在OS X中,BLAS已内置到Accelerate Framework中,因此在makefile中,我通过 -framework Accelerate
链接了lib,在cpp中,我还通过#include< Accelerate/Accelerate包含了头文件..h>
I created a matrix multiplicity code for an assignment but could not get the function working, so I suspect it is the BLAS lib not linked properly.
In OS X, the BLAS has been built into the Accelerate Framework, so in makefile I linked the lib by -framework Accelerate
and in cpp I also include the header by #include<Accelerate/Accelerate.h>
在编译过程中,我的错误是:
During compilation, my error is:
Undefined symbols for architecture x86_64:
"dgemm_(char*, char*, int*, int*, int*, double*, double*, int*, double*, int*, double*, double*, int*)"
所以我创建了一个简单的测试代码,但是在编译过程中仍然出现错误:
So I created a simple test code but I still get the error during compilation:
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;
}
推荐答案
Per the documentation, Accelerate.framework prefixes all BLAS functions with cblas_
. For example, the dgemm
function is declared as
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 );
这篇关于编译期间无法从Accelerate Framework中链接BLAS -OS Yosemite 10.0.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!