[petsc-users] Blas undefined references when build an app linking to a shared library that is linked to a static Petsc library

Thuc Bui bui at calcreek.com
Fri Oct 23 19:21:32 CDT 2020


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

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20201023/8c48e6d4/attachment-0001.html>


More information about the petsc-users mailing list