Cannot link the BLAS from Accelerate Framework during compilation -OS Yosemite 10.0.5

百般思念 提交于 2021-01-28 01:59:15

问题


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 Accelerateand 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.

My simple test code is compiled with

 clang++  -o test_2.exe test_2.cpp -framework Accelerate

My simple code is :

#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;
}

回答1:


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 ); 


来源:https://stackoverflow.com/questions/33341127/cannot-link-the-blas-from-accelerate-framework-during-compilation-os-yosemite-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!