Ubuntu 20.04.5 LTS下链接LAPACK库时出现未定义引用错误的求助
Ubuntu 20.04.5 LTS下链接LAPACK库时出现未定义引用错误的求助
我在新的Ubuntu机器(补充:Ubuntu 20.04.5 LTS)上使用LAPACK时遇到了问题。我已经通过apt-get安装了liblapack-dev和libblas-dev,但运行一段在其他机器上正常工作的代码时,编译环节报错了。
下面是我的测试代码:
#include <stdlib.h> #include <stdio.h> /* DGESV prototype */ extern void dgesv( int* n, int* nrhs, double* a, int* lda, int* ipiv, double* b, int* ldb, int* info ); /* Auxiliary routines prototypes */ extern void print_matrix( char* desc, int m, int n, double* a, int lda ); extern void print_int_vector( char* desc, int n, int* a ); /* Parameters */ #define N 5 #define NRHS 3 #define LDA N #define LDB N /* Main program */ int main() { /* Locals */ int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info; /* Local arrays */ int ipiv[N]; double a[LDA*N] = { 6.80, -2.11, 5.66, 5.97, 8.23, -6.05, -3.30, 5.36, -4.44, 1.08, -0.45, 2.58, -2.70, 0.27, 9.04, 8.32, 2.71, 4.35, -7.17, 2.14, -9.67, -5.14, -7.26, 6.08, -6.87 }; double b[LDB*NRHS] = { 4.02, 6.19, -8.22, -7.57, -3.03, -1.56, 4.00, -8.67, 1.75, 2.86, 9.81, -4.09, -4.57, -8.61, 8.99 }; /* Executable statements */ printf( " DGESV Example Program Results\n" ); /* Solve the equations A*X = B */ dgesv( &n, &nrhs, a, &lda, ipiv, b, &ldb, &info ); /* Check for the exact singularity */ if( info > 0 ) { printf( "The diagonal element of the triangular factor of A,\n" ); printf( "U(%i,%i) is zero, so that A is singular;\n", info, info ); printf( "the solution could not be computed.\n" ); exit( 1 ); } /* Print solution */ print_matrix( "Solution", n, nrhs, b, ldb ); /* Print details of LU factorization */ print_matrix( "Details of LU factorization", n, n, a, lda ); /* Print pivot indices */ print_int_vector( "Pivot indices", n, ipiv ); exit( 0 ); } /* End of DGESV Example */ /* Auxiliary routine: printing a matrix */ void print_matrix( char* desc, int m, int n, double* a, int lda ) { int i, j; printf( "\n %s\n", desc ); for( i = 0; i < m; i++ ) { for( j = 0; j < n; j++ ) printf( " %6.2f", a[i+j*lda] ); printf( "\n" ); } } /* Auxiliary routine: printing a vector of integers */ void print_int_vector( char* desc, int n, int* a ) { int j; printf( "\n %s\n", desc ); for( j = 0; j < n; j++ ) printf( " %6i", a[j] ); printf( "\n" ); }
我用下面的命令编译:
gcc -Wall test.c -lm -lblas -llapack
结果出现了以下错误:
/usr/bin/ld: /tmp/ccTfUyXO.o: in function `main': test.c:(.text+0x2e3): undefined reference to `dgesv' collect2: error: ld returned 1 exit status
我其他调用不同LAPACK例程的复杂代码也遇到了完全相同的问题。我尝试过在-llapack后面加上-L参数指定LAPACK文件所在的目录,但也没有解决问题。有没有人知道可能是什么原因导致的?
备注:内容来源于stack exchange,提问作者T. Skora
相关产品推荐
相关产品推荐

