Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: Re: [OMPI users] [EXTERNAL] Re: mpicc link shouldn't add -ldl and -lhwloc
From: Jed Brown (jed_at_[hidden])
Date: 2012-05-27 13:52:06

On Wed, May 23, 2012 at 8:29 AM, Barrett, Brian W <bwbarre_at_[hidden]>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

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
$ 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/ => (0x00007fff741ff000) => /lib/ (0x00007f135eac7000) => /usr/lib/ (0x00007f135e83f000) => /usr/lib/
(0x00007f135e608000) => /usr/lib/ (0x00007f135e369000) => /usr/lib/ (0x00007f135e13c000) => /usr/lib/ (0x00007f135df39000) => /usr/lib/
(0x00007f135dd30000) => /usr/lib/ (0x00007f135db12000) => /usr/lib/ (0x00007f135d906000) => /usr/lib/ (0x00007f135d5cc000) => /usr/lib/ (0x00007f135d3b6000) => /lib/ (0x00007f135d1ad000) => /lib/ (0x00007f135ceb8000) => /lib/ (0x00007f135cb17000)
        /lib/ (0x00007f135f012000) => /usr/lib/ (0x00007f135c906000) => /usr/lib/ (0x00007f135c6dc000) => /usr/lib/ (0x00007f135c4d8000) => /usr/lib/ (0x00007f135c2d1000) => /lib/ (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.)