Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link error undefined reference to `dgels_' in Lapack

Tags:

linux

lapack

I followed this below webpage to install ATLAS + Lapack in linux :

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

After that , I try to run an sample in http://www.netlib.org/lapack/lapacke.html

the sample code :

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

I have found out the build library has no iblapacke.a , so I build this library by myslef

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

Then , finally I have the iblapacke.a now , so I compile the sample above by :

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

I get the following errors :

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_'

After I google , I have found : 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 

There is a function dgels , without underline , and in

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

I think the underline is added for accident ,

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

I think I should try to not avoid underline like build "dgels" not to "dgels" while build liblapack.a ,means I should change something build Lapack and ATLAS , just don't know how to do it ....Any suggestion is appreciated !!

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

I have no idea if related , -Ddgels=dgels_ is added , the same link error !!

like image 939
barfatchen Avatar asked Feb 17 '23 08:02

barfatchen


2 Answers

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

for example:

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

the order of lapacke > lapack > refblas is important... also if you don't want to use the double step gcc gfortran, use -lgfortran

like image 190
trigal Avatar answered Feb 19 '23 21:02

trigal


I had the exact same problem. You need to do it as follows:

gcc(or g++) -c -O3 -I ../include -o test.o test.c

and then

gfortran test.o ../liblapacke.a ../liblapack.a ../blas.a -o test.exe

You can then run it like so:

./test.exe

Basically, you need to follow the gcc compile with a gfortran compile. The -c option in the first command forces gcc to skip the linker. gfortran is then used to link the libraries.

You can learn more by looking at the makefile for the examples provided with LAPACKE.

like image 33
Salmon Strikes Avatar answered Feb 19 '23 23:02

Salmon Strikes