Hi Barry,

 

Thank you very much for getting back to me, and for the link to lapack forum. I 
really appreciate your taking the time to look this up. I found the same site 
earlier and believed the undefined references were related to xblas, but didn’t 
see how they were able to pollute the libfblas and libflapack libraries. 
Anyhow, I found a work around! Since I was able to compiled, linked and 
executed a window app using static Petsc with f2cblas and f2clapack built by 
Visual Studio 2015, I did the same for Ubuntu build, configure static Petsc 
without gfotran and use libf2cblas and libf2clapack. All the linking issues 
went away! Problem is solved!

 

Many thanks again,

Thuc

 

 

From: Barry Smith [mailto:[email protected]] 
Sent: Friday, October 23, 2020 5:37 PM
To: Thuc Bui
Cc: petsc-users
Subject: Re: [petsc-users] Blas undefined references when build an app linking 
to a shared library that is linked to a static Petsc library

 

 

  I found

 

http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=2 
<http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=2&t=1730> &t=1730

 

but I do not understand it.

 

I am pretty sure PETSc is not providing in anyway even through its packages 
like fblaslapack blas_sgemv_x anyway I would focus on figuring out where those 
are coming from. Normal compilers won't need them. Do you use them? 

 

  Good luck

 

   Barry





On Oct 23, 2020, at 7:21 PM, Thuc Bui <[email protected]> wrote:

 

Dear Petsc Users, 

 

I hope someone out there has already encountered the same linking problem and 
already figured this out, or has some idea how to resolve this issue. I have 
google searched but haven’t found any solution.

 

I successfully ported Petsc 3.13.5 both as shared and static libraries in both 
Windows 10 (Visual Studio 2015, no Fortran) and Ubuntu 20.4 (gcc, g++. gfortran 
9.3), and successfully run “make check” in all. I am also able to build my own 
shared libraries linked to either shared or static Petsc library in both 
platforms. I was also able to link and execute my application to either of 
these shared libraries in Windows. Unfortunately, I could only get my app to 
link and execute with the shared library linked to the shared Petsc library in 
Ubuntu, but not with the static Petsc library.

 

On Ubuntu, below is how I build Petsc static library, which produces three 
libraries: libpetsc.a, libfblas.a and libflapack.a

 

./configure CFLAGS="-fPIC" CXXFLAGS="-fPIC" FFLAGS="-fPIC" -with-cc=gcc 
--with-cxx=g++ --with-fc=gfortran --with-openmp --with-debugging=0 
--download-fblaslapack --with-mpi=0 --with-shared-libraries=0

 

Below is the make output on how I build my shared library, cPoissons.so linking 
to the static Petsc. Please note that I have to use --allow-multiple-definition 
to override the redefinition errors in lapack and blas. I also use 
--whole-archive to make sure the shared library has all the required 
information from lapack and blas.

 

gcc -fPIC -c -o gcc/matrixUtil.o matrixUtil.c 

                -I/home/bbwannabe/Documents/Petsc/latest/include 

                -I/home/bbwannabe/Documents/Petsc/latest/include/petsc/private 

                
-I/home/bbwannabe/Documents/Petsc/latest/gcc-x64SRelease/include              

gcc -fPIC -c -o gcc/PetscSolver.o PetscSolver.c 

                -I/home/bbwannabe/Documents/Petsc/latest/include 

                -I/home/bbwannabe/Documents/Petsc/latest/include/petsc/private 

                -I/home/bbwannabe/Documents/Petsc/latest/gcc-x64SRelease/include

gcc -fPIC -c -o gcc/LinearSystemSolver.o LinearSystemSolver.c 

                -I/home/bbwannabe/Documents/Petsc/latest/include 

                -I/home/bbwannabe/Documents/Petsc/latest/include/petsc/private 

                -I/home/bbwannabe/Documents/Petsc/latest/gcc-x64SRelease/include

gcc -fPIC -c -o gcc/cPoisson.o cPoisson.c 

                -I/home/bbwannabe/Documents/Petsc/latest/include 

                -I/home/bbwannabe/Documents/Petsc/latest/include/petsc/private 

                -I/home/bbwannabe/Documents/Petsc/latest/gcc-x64SRelease/include

gcc -fPIC -fopenmp -shared -o gcc/cPoissons.so gcc/matrixUtil.o 
gcc/PetscSolver.o gcc/LinearSystemSolver.o gcc/cPoisson.o 

                -L/home/bbwannabe/Documents/Petsc/latest/gcc-x64SRelease/lib 

                -Wl,--allow-multiple-definition 

                -Wl,--whole-archive -lpetsc -lflapack -lfblas 
-Wl,--no-whole-archive

 

However, when I build my app linking to the above shared library cPoissons.so. 
gfortran complains about undefined references, which seem to be from blas as 
shown below from the output of make. Has anyone seen this kind of linking 
problem before? 

 

Many thanks for your help.

Thuc Bui

Senior R&D Engineer

Calabazas Creek Research, Inc.

(650) 948-5361 (Office)

 

gfortran -fPIC -o sPoisson3D Poisson3D.f 
-L/home/bbwannabe/Documents/Nemesis/cPoisson/gcc -l:cPoissons.so 

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_sgemv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zgemv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_cgbmv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_cgbmv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_chemv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_csymv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_sgbmv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_dgemv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zsymv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_csymv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_ssymv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_ssymv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zgemv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_dsymv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zhemv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zgbmv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_sgemv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_chemv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_dgemv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_cgemv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_sgbmv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zgbmv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_dgbmv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zhemv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_zsymv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_dsymv_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_dgbmv2_x_'

/usr/bin/ld: /home/bbwannabe/Documents/Nemesis/cPoisson/gcc/cPoissons.so: 
undefined reference to `blas_cgemv_x_'

collect2: error: ld returned 1 exit status

make: *** [makefile:6: sPoisson3D] Error 1

 

Reply via email to