ATLAS gemm link undefined link to 'cblas_sgemm'

This is the first time I'm trying to use ATLAS. I can't tie it right. Here is a very simple sgemm program:

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

When I compile it on a linux platform with a standard ATLAS installation, it gives a binding error:

 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 

As you can see, I tried to give different combinations of libraries, but did not help. What am I doing wrong?

+8
c ++ c blas atlas
source share
2 answers

You need

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

because you are compiling with g++ .

Or you can even do

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

to be able to compile as C.

When you compile in C ++, the names are expected to be garbled. But since cblas is compiled in C, exported characters have no malformed names. Therefore, you should instruct the compiler to look for C style characters.

+11
source share

Be careful with the code. This is β€œC,” not C. So, the code finally

 #ifdef __cplusplus extern "C" { #endif //__cplusplus #include <cblas.h> #ifdef __cplusplus } #endif //__cplusplus 
+1
source share

All Articles