[petsc-users] .pc file does not include dependencies
Arne Morten Kvarving
arne.morten.kvarving at sintef.no
Wed Nov 25 07:50:59 CST 2015
On 25/11/15 14:07, Matthew Knepley wrote:
> On Wed, Nov 25, 2015 at 6:16 AM, Arne Morten Kvarving
> <arne.morten.kvarving at sintef.no> wrote:
>
> hi,
>
> a while back i was told to use the .pc file for petsc if i wanted
> pkgconfig style (duh) configuration.
> i used to use a (confusingly named) PETScConfig.cmake file for
> this, which was not intended for such use.
>
> problem now is that the pc file of petsc is a bit broken.
>
> in particular, i want to link petsc static, but not all the
> dependencies. if i build petsc (static or not),
> the lib entry is listed as
>
> Libs: -L<path-to-petsc-configuration>/lib -lpetsc
>
> now, the dependencies are listed in
>
> Libs.private: /usr/lib/liblapack.a /usr/lib/libblas.a libX11.a
> libpthread.a libssl.a libcrypto.a libhwloc.a libm.a
> -L/usr/lib/gcc/x86_64-linux-gnu/4.9 -L/usr/lib/x86_64-linux-gnu
> -L/lib/x86_64-linux-gnu -lgfortran -lm -lgfortran -lm -lquadmath
> -lm -L/usr/lib/gcc/x86_64-linux-gnu/4.9
> -L/usr/lib/x86_64-linux-gnu -L/lib/x86_64-linux-gnu -lstdc++
> -L/usr/lib/gcc/x86_64-linux-gnu/4.9 -L/usr/lib/x86_64-linux-gnu
> -L/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -ldl -lgcc_s
> -ldl -ldl
>
> which are for a totally static link (you'd use --static with
> pkg-config to obtain it).
>
> the problem with a totally static link, however, is that
> pkg-config returns this:
>
> pkg-config --static --libs PETSc ->
>
> /usr/lib/liblapack.a /usr/lib/libblas.a libX11.a libpthread.a
> libssl.a libcrypto.a libhwloc.a libm.a
> -L/home/akva/kode/petsc/current/linux-gnu-cxx-opt/lib
> -L/usr/lib/gcc/x86_64-linux-gnu/4.9 -lpetsc -lgfortran -lquadmath
> -lm -lstdc++ -lgcc_s -ldl
>
> which breaks at linking because petsc won't see any of the symbols
> in those .a files before (static link is order dependent).
>
>
> I do not understand this explanation.
>
> 1) Why does the link fail? Please send the error.
it's because with static linking, the order of libraries matter. if you do
-lfoo -lbar
the linker will see the symbols in the bar library when linking foo, but
not the other way around.
thus the linker do not see the symbols in e.g. libX11.a when linking
petsc and you get a lots of inker errors,
random line;
xops.c:(.text+0x2a9): undefined reference to `XSetForeground'
xops.c:(.text+0x3e0): undefined reference to `XDrawLine'
/home/akva/kode/petsc/current/linux-gnu-cxx-opt/lib/libpetsc.a(xops.o):
In function `PetscDrawArrow_X(_p_PetscDraw*, double, double, double,
double, int)':
>
> 2) Is pkgconfig changing/filtering the link line? That would seem like
> a bug in pkgconfig.
yes, pkg-config is behaving very weird. i have no idea of the logic
here, it's likely a bug.
if I
1) move Libs.private below Libs in the .pc file
2) replace the absolute references to archive foo.a with -lfoo
it works. i.e.
using http://paste.ubuntu.com/13502223/ (ignore the irrelevant changes,
that is using the variables instead of absolute paths), i get
/usr/lib/liblapack.a /usr/lib/libblas.a libX11.a libpthread.a libssl.a
libcrypto.a libhwloc.a libm.a
-L/home/akva/kode/petsc/current/linux-gnu-cxx-opt/lib
-L/usr/lib/gcc/x86_64-linux-gnu/4.9 -lpetsc -lgfortran -lquadmath -lm
-lstdc++ -lgcc_s -ldl
which breaks (so step 1 is not enough).
if i however use http://paste.ubuntu.com/13502228/
i get
-L/home/akva/kode/petsc/current/linux-gnu-cxx-opt/lib
-L/usr/lib/gcc/x86_64-linux-gnu/4.9 -lpetsc -llapack -lblas -lX11
-lpthread -lssl -lcrypto -lhwloc -lm -lstdc++ -lgcc_s -ldl
as wanted (missing a few -L's in principle for the last file).
this is with pkg-config 0.26 (ubuntu trusty).
arnem
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20151125/3fad4e46/attachment-0001.html>
More information about the petsc-users
mailing list