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

We've tossed around ideas such as having the wrappers always assume dynamic linking (e.g., only include a minimum of libraries), and then add another wrapper option like --wrapper:static (or whatever) to know when to add in all the dependent libraries. Or possibly even look for some popular linker options like --static, or some such (which we've tried to avoid, because that can turn into a slippery slope), but such switches aren't always necessary for MPI-only-static (vs. completely-100%-static) linking. It gets even fuzzier when both libmpi.so and libmpi.a are present. Which way should we assume?

Another problem is backwards compatibility -- users who are currently statically linking will assume the old behavior (of not needing to specify anything additional).

> 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.

Fair enough. But we've never been able to come up with a rational way to do it (note that pkg-config has its own problems -- OMPI provides pkg-config files in addition to wrapper compilers, but they don't fix everything, either).

We have users who both --enable-static and --enable-shared (meaning: both libmpi.so and libmpi.a are present). And therefore we've come down on the conservative side of adding in whatever is necessary for static linking.

> (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.)

I suppose, but it does depend on how you define "problem". The linker will ignore any unused libraries -- so it's a problem like lint is a problem. It's annoying, but it doesn't do any harm.