gpt4 book ai didi

linux - Lapack 中链接错误 undefined reference to `dgels_'

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:38 31 4
gpt4 key购买 nike

我按照以下网页在 linux 中安装 ATLAS + Lapack:

http://math-atlas.sourceforge.net/atlas_install/node6.html

bunzip2 -c atlas3.10.1.tar.bz2 | tar xfm -    # create SRCdir
mv ATLAS ATLAS3.10.1 # get unique dir name
cd ATLAS3.10.1 # enter SRCdir
mkdir Linux_C2D64SSE3 # create BLDdir
cd Linux_C2D64SSE3 # enter BLDdir
../configure -b 64 -D c -DPentiumCPS=2400 \ # configure command
--prefix=/home/whaley/lib/atlas \ # install dir
--with-netlib-lapack-tarfile=/home/whaley/dload/lapack-3.4.2.tgz
make build # tune & build lib
make check # sanity check correct answer
make ptcheck # sanity check parallel
make time # check if lib is fast
make install # copy libs to install dir

在那之后,我尝试在 http://www.netlib.org/lapack/lapacke.html

示例代码:

#include <stdio.h>
#include <lapacke.h>

int main (int argc, const char * argv[])
{
double a[5*3] = {1,2,3,4,5,1,3,5,2,4,1,4,2,5,3};
double b[5*2] = {-10,12,14,16,18,-3,14,12,16,16};
lapack_int info,m,n,lda,ldb,nrhs;
int i,j;
m = 5;
n = 3;
nrhs = 2;
lda = 5;
ldb = 5;

info = LAPACKE_dgels(LAPACK_COL_MAJOR,'N',m,n,nrhs,a,lda,b,ldb);

for(i=0;i<n;i++)
{
for(j=0;j<nrhs;j++)
{
printf("%lf ",b[i+ldb*j]);
}
printf("\n");
}
return(info);
}

我发现构建库没有 iblapacke.a ,所以我通过 myslef 构建这个库

cd lapack-3.4.2
cp make.inc.example make.inc
cd lapacke
make

然后,我终于有了 iblapacke.a,所以我通过以下方式编译上面的示例:

g++ test3.cpp liblapacke.a -o test3.exe  

我收到以下错误:

liblapacke.a(lapacke_dgels_work.o): In function `LAPACKE_dgels_work':
lapacke_dgels_work.c:(.text+0x1dd): undefined reference to `dgels_'
lapacke_dgels_work.c:(.text+0x2b7): undefined reference to `dgels_'

在我谷歌之后,我发现: http://www.netlib.org/lapack/explore-html/d7/d3b/group__double_g_esolve.html

Functions/Subroutines 
subroutine dgels (TRANS, M, N, NRHS, A, LDA, B, LDB, WORK, LWORK, INFO)
DGELS solves overdetermined or underdetermined systems for GE matrices

有一个函数 dgels ,没有下划线,在

http://shtools.ipgp.fr/www/faq.html#l4

我认为加下划线是为了意外,

nm -A liblapacke.a |grep "dgels_"

liblapacke.a:lapacke_dgels.o: U LAPACKE_dgels_work
liblapacke.a:lapacke_dgels_work.o: U LAPACKE_dge_trans
liblapacke.a:lapacke_dgels_work.o:0000000000000000 T LAPACKE_dgels_work
liblapacke.a:lapacke_dgels_work.o: U LAPACKE_xerbla
liblapacke.a:lapacke_dgels_work.o: U dgels_
liblapacke.a:lapacke_dgels_work.o: U free
liblapacke.a:lapacke_dgels_work.o: U malloc

我认为我应该在构建 liblapack.a 时尽量避免像构建“dgels”而不是“dgels”这样的下划线,这意味着我应该改变构建 Lapack 和 ATLAS 的东西,只是不知道该怎么做....任何建议表示赞赏!!

更新:http://software.intel.com/sites/products/documentation/doclib/mkl_sa/11/mkl_lapack_examples/c_bindings.htm

不知道有没有关联,加了-Ddgels=dgels_,同样链接错误!!

最佳答案

见: http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=12&t=3336

例如:

gcc LinearEquation.c -Ilapack-3.5.0/lapacke/include/ -Llapack-3.5.0 -llapacke -llapack -lrefblas -lgfortran -o LinearEquation

lapacke > lapack > refblas 的顺序很重要...如果您不想使用双步 gcc gfortran,请使用 - lgfortran

关于linux - Lapack 中链接错误 undefined reference to `dgels_',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15152578/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com