我无法链接简单的cblas程序,这是我的最小例子:
extern "C"
{
#include <cblas.h>
}
#include <iostream>
int main() {
int lda = 3;
float A[] = { 0.11, 0.12, 0.13,
0.21, 0.22, 0.23 };
int ldb = 2;
float B[] = { 1011, 1012,
1021, 1022,
1031, 1032 };
int ldc = 2;
float C[] = { 0.00, 0.00,
0.00, 0.00 };
cblas_sgemm(CblasRowMajor,
CblasNoTrans,
CblasNoTrans,
2, 2, 3, 1.0, A, lda, B, ldb, 0.0, C, ldc);
std::cout << "[ " << C[0] << ", " << C[1] << "\n " << C[2]
<< ", " << C[3] << " ]\n";
}
现在我试图用g++ -lcblas test.cpp
编译程序,但这给了我
gdev-home@gdev-home:~/Documents$ g++ -lcblas test.cpp
/tmp/ccEwRr40.o: In function `main':
test.cpp:(.text+0x112): undefined reference to `cblas_sgemm'
collect2: error: ld returned 1 exit status
这意味着它没有正确链接。奇怪的是我做有cblas库,我通过atlas安装它们
gdev-home@gdev-home:~/Documents$ dpkg --get-selections | grep atlas
libatlas-base-dev install
libatlas-dev install
libatlas3-base install
如果你看看/usr/lib
我有
gdev-home@gdev-home:/usr/lib$ ls | grep blas
libblas
libblas.a
libblas.so
libblas.so.3
libblas.so.3gf
libcblas.a
libcblas.so
libcblas.so.3
libcblas.so.3gf
libf77blas.a
libf77blas.so
libf77blas.so.3
libf77blas.so.3gf
有谁知道为什么这个程序无法链接?
答案 0 :(得分:3)
我认为-lcblas arg应该在test.cpp之后。