<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 25/11/15 14:07, Matthew Knepley wrote:<br>
    <div class="moz-forward-container">
      <blockquote
cite="mid:CAMYG4GnbfwChfVJaJ6Eiti2xD1GWea4j53_itY7A1t9ii3sy6g@mail.gmail.com"
        type="cite">
        <meta http-equiv="Content-Type" content="text/html;
          charset=utf-8">
        <div dir="ltr">
          <div class="gmail_extra">
            <div class="gmail_quote">On Wed, Nov 25, 2015 at 6:16 AM,
              Arne Morten Kvarving <span dir="ltr"><<a
                  moz-do-not-send="true"
                  class="moz-txt-link-abbreviated"
                  href="mailto:arne.morten.kvarving@sintef.no"><a class="moz-txt-link-abbreviated" href="mailto:arne.morten.kvarving@sintef.no">arne.morten.kvarving@sintef.no</a></a>></span>
              wrote:<br>
              <blockquote class="gmail_quote" style="margin:0 0 0
                .8ex;border-left:1px #ccc solid;padding-left:1ex">hi,<br>
                <br>
                a while back i was told to use the .pc file for petsc if
                i wanted pkgconfig style (duh) configuration.<br>
                i used to use a (confusingly named) PETScConfig.cmake
                file for this, which was not intended for such use.<br>
                <br>
                problem now is that the pc file of petsc is a bit
                broken.<br>
                <br>
                in particular, i want to link petsc static, but not all
                the dependencies. if i build petsc (static or not),<br>
                the lib entry is listed as<br>
                <br>
                Libs: -L<path-to-petsc-configuration>/libĀ  -lpetsc<br>
                <br>
                now, the dependencies are listed in<br>
                <br>
                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<br>
                <br>
                which are for a totally static link (you'd use --static
                with pkg-config to obtain it).<br>
                <br>
                the problem with a totally static link, however, is that
                pkg-config returns this:<br>
                <br>
                pkg-config --static --libs PETSc -><br>
                <br>
                /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<br>
                <br>
                which breaks at linking because petsc won't see any of
                the symbols in those .a files before (static link is
                order dependent).<br>
              </blockquote>
              <div><br>
              </div>
              <div>I do not understand this explanation.</div>
              <div><br>
              </div>
              <div>1) Why does the link fail? Please send the error.</div>
            </div>
          </div>
        </div>
      </blockquote>
      it's because with static linking, the order of libraries matter.
      if you do<br>
      <br>
      -lfoo -lbar<br>
      <br>
      the linker will see the symbols in the bar library when linking
      foo, but not the other way around. <br>
      thus the linker do not see the symbols in e.g. libX11.a when
      linking petsc and you get a lots of inker errors,<br>
      <br>
      random line; <br>
      <br>
      xops.c:(.text+0x2a9): undefined reference to `XSetForeground'<br>
      xops.c:(.text+0x3e0): undefined reference to `XDrawLine'<br>
      /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)':<br>
      <br>
      <br>
      <blockquote
cite="mid:CAMYG4GnbfwChfVJaJ6Eiti2xD1GWea4j53_itY7A1t9ii3sy6g@mail.gmail.com"
        type="cite">
        <div dir="ltr">
          <div class="gmail_extra">
            <div class="gmail_quote">
              <div><br>
              </div>
              <div>2) Is pkgconfig changing/filtering the link line?
                That would seem like a bug in pkgconfig.</div>
            </div>
          </div>
        </div>
      </blockquote>
      yes, pkg-config is behaving very weird. i have no idea of the
      logic here, it's likely a bug.<br>
      <br>
      if I<br>
      1) move Libs.private below Libs in the .pc file<br>
      2) replace the absolute references to archive foo.a with -lfoo<br>
      <br>
      it works. i.e.<br>
      <br>
      using <a moz-do-not-send="true" class="moz-txt-link-freetext"
        href="http://paste.ubuntu.com/13502223/">http://paste.ubuntu.com/13502223/</a>
      (ignore the irrelevant changes, that is using the variables
      instead of absolute paths), i get<br>
      /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<br>
      <br>
      which breaks (so step 1 is not enough).<br>
      <br>
      if i however use <a moz-do-not-send="true"
        class="moz-txt-link-freetext"
        href="http://paste.ubuntu.com/13502228/">http://paste.ubuntu.com/13502228/</a><br>
      <br>
      i get<br>
      <br>
      -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 <br>
      <br>
      as wanted (missing a few -L's in principle for the last file).<br>
      <br>
      this is with pkg-config 0.26 (ubuntu trusty).<br>
      <br>
      arnem<br>
      <br>
    </div>
    <br>
  </body>
</html>