Reordering of Libs

Daniel Macks dmacks at
Thu Jan 22 08:24:06 PST 2009

On Thu, Jan 22, 2009 at 11:13:47AM -0500, Christopher Hulbert wrote:
> On Thu, Jan 22, 2009 at 11:03 AM, Daniel Macks <dmacks at> wrote:
> > On Thu, Jan 22, 2009 at 10:09:57AM -0500, Christopher Hulbert wrote:
> >> I searched the archive and found a few messages by 'bora.sahin at
> >>' on this topic, but never a response. I have a .pc file
> >> that has a library requiring linking in the fortran compiler's
> >> libraries. These are added with appropriate '-Bstatic' and -Bdynamic'
> >> flags to link in static versions of the compiler libraries. Running
> >> pkg-config --libs obviously reorders that line and messes that up. Is
> >> there an intentional reason for this, or just an implementation
> >> artifact?
> >
> > Could you give us a sample .pc and what you expect vs what happens?
> The .pc file is below. When I run pkg-config --libs, the -Bstatic and
> -Bdynamic flags get moved up front presumably treated as other libs.
> What I would like, is the -Bstatic to stay ordered with the libs (just
> like the Libs line).
> [chulbert at fourier pkgconfig]$ PKG_CONFIG_PATH=. pkg-config --libs scats
> -Bstatic -Bdynamic
> -L/home/chulbert/isl-scrd/x86_64-unknown-linux-gnu/lib64
> -L/opt/matio/linux86-64/1.5.0/pgi-8.0/lib
> -L/opt/hdf5/linux86-64/1.8.2/pgi-8.0/lib
> -L/opt/pgi/linux86-64/8.0-3/libso -L/opt/pgi/linux86-64/8.0-3/lib
> -L/usr/lib/gcc/x86_64-redhat-linux/4.1.2 -lscats -lseke -lvsip
> -lscatsio -lmatio -lhdf5 -lz -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl
> -lpgftnrtl -lnspgc -lpgc -lrt -lpthread -lm
scats.pc excerpt:
> prefix=/home/chulbert/isl-scrd/x86_64-unknown-linux-gnu
> libdir=${exec_prefix}/lib64
> Libs: -L${libdir} -lscats -lseke
> -L/home/chulbert/isl-scrd/x86_64-unknown-linux-gnu/lib64 -lvsip
> -lscatsio -L/opt/matio/linux86-64/1.5.0/pgi-8.0/lib
> -L/opt/hdf5/linux86-64/1.8.2/pgi-8.0/lib -lmatio -lhdf5 -lz
> -L/usr/lib64 -lz  -L/opt/pgi/linux86-64/8.0-3/libso
> -L/opt/pgi/linux86-64/8.0-3/lib -L/usr/lib64
> -L/usr/lib/gcc/x86_64-redhat-linux/4.1.2 -Bstatic -lpgf90 -lpgf90_rpm1
> -lpgf902 -lpgf90rtl -lpgftnrtl -lnspgc -lpgc -Bdynamic -lrt -lpthread
> -lm -Bstatic -Bdynamic

You can use -Wl, to tie multiple linker flags together as a single
word with no whitespace. This single chunk will not get broken by


because the whole thing is a single word. The location of that word in
the "pkg-config --libs" output relative to other flags might vary (I
don't know what pkg-config's algorithm is for ordering!), but the -B
wrappers around those -l flags will not get lost.


Daniel Macks
dmacks at

More information about the pkg-config mailing list