On Wed, May 23, 2012 at 8:29 AM, Barrett, Brian W <bwbarre@sandia.gov> wrote:
>I should add the caveat that they are need when linking statically, but
>not when using shared libraries.

And therein lies the problem.  We have a number of users who build Open
MPI statically and even some who build both static and shared libraries in
the same build.  We've never been able to figure out a reasonable way to
guess if we need to add -lhwloc or -ldl, so we add them.  It's better to
list them and have some redundant dependencies (since you have to have the
library anyways) than to not list them and have odd link errors.

So pkg-config has the --static option for exactly this reason. Let's look at Cairo as an example.

$ cat /usr/lib/pkgconfig/cairo.pc 
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: cairo
Description: Multi-platform 2D graphics library
Version: 1.12.2

Requires.private:   gobject-2.0 glib-2.0       pixman-1 >= 0.22.0    fontconfig >= 2.2.95 freetype2 >= 9.7.3   libpng xcb-shm xcb >= 1.6 xcb-render >= 1.6 xrender >= 0.6 x11 
Libs: -L${libdir} -lcairo
Libs.private:            -lz -lz         
Cflags: -I${includedir}/cairo

$ pkg-config cairo --libs
-lcairo
$ pkg-config cairo --libs --static
-pthread -lcairo -lgobject-2.0 -lffi -lpixman-1 -lfontconfig -lexpat -lfreetype -lbz2 -lpng15 -lz -lm -lxcb-shm -lxcb-render -lXrender -lglib-2.0 -lrt -lpcre -lX11 -lpthread -lxcb -lXau -lXdmcp
$ ldd /usr/lib/libcairo.so
        linux-vdso.so.1 =>  (0x00007fff741ff000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x00007f135eac7000)
        libpixman-1.so.0 => /usr/lib/libpixman-1.so.0 (0x00007f135e83f000)
        libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00007f135e608000)
        libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x00007f135e369000)
        libpng15.so.15 => /usr/lib/libpng15.so.15 (0x00007f135e13c000)
        libxcb-shm.so.0 => /usr/lib/libxcb-shm.so.0 (0x00007f135df39000)
        libxcb-render.so.0 => /usr/lib/libxcb-render.so.0 (0x00007f135dd30000)
        libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f135db12000)
        libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00007f135d906000)
        libX11.so.6 => /usr/lib/libX11.so.6 (0x00007f135d5cc000)
        libz.so.1 => /usr/lib/libz.so.1 (0x00007f135d3b6000)
        librt.so.1 => /lib/librt.so.1 (0x00007f135d1ad000)
        libm.so.6 => /lib/libm.so.6 (0x00007f135ceb8000)
        libc.so.6 => /lib/libc.so.6 (0x00007f135cb17000)
        /lib/ld-linux-x86-64.so.2 (0x00007f135f012000)
        libbz2.so.1.0 => /usr/lib/libbz2.so.1.0 (0x00007f135c906000)
        libexpat.so.1 => /usr/lib/libexpat.so.1 (0x00007f135c6dc000)
        libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f135c4d8000)
        libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f135c2d1000)
        libdl.so.2 => /lib/libdl.so.2 (0x00007f135c0cd000)

Now I'm not saying that Open MPI should commit to pkg-config instead of wrapper compilers, but the concept of linking differently for static versus shared libraries is something that should be observed.

(Over-linking is an ongoing problem with HPC-oriented packages. We are probably all guilty of it, but tools like pkg-config don't handle multiple configurations well and I don't know of a similar system that manages both static/shared and multi-configuration well.)