Purpose of --static and Requires.private

Niklas Gürtler profclonk at gmx.de
Fri Sep 28 10:38:40 PDT 2012


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear readers,

i wonder why there is the --static flag. Consider this example:

pango.pc makes use of the "Requires.private" field, requiring
"gmodule-no-export-2.0" (-lgmodule-2.0 and others) only when --static is
specified:
~ $ pkg-config --cflags --libs pango
- -pthread -I/usr/include/pango-1.0 -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include  -lpango-1.0 -lgobject-2.0 -lglib-2.0
~ $ pkg-config --cflags --libs --static pango
- -pthread -I/usr/include/pango-1.0 -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include  -pthread -lpango-1.0 -lgmodule-2.0 -ldl
-lgobject-2.0 -lffi -lglib-2.0 -lrt -lpcre


When linking a dummy program (dynamically) against pango, once the
"normal" way, and once with "--static" ...
~ $ gcc helloworld.c -o helloworld1 `pkg-config --cflags --libs pango`
~ $ gcc helloworld.c -o helloworld2 `pkg-config --cflags --libs --static
pango`

... and then analyzing the library dependencies of the resulting files ...
~ $ ldd helloworld1 | sort
    libc.so.6 => /usr/lib/libc.so.6 (0x00007f5c5b627000)
    libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f5c5a6b5000)
    libffi.so.6 => /usr/lib/libffi.so.6 (0x00007f5c5a8b9000)
    libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f5c5bbea000)
    libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x00007f5c5b423000)
    libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007f5c5bede000)
    libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x00007f5c5ad1f000)
    /lib/ld-linux-x86-64.so.2 (0x00007f5c5c377000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007f5c5af21000)
    libpango-1.0.so.0 => /usr/lib/libpango-1.0.so.0 (0x00007f5c5c12c000)
    libpcre.so.1 => /usr/lib/libpcre.so.1 (0x00007f5c5aac1000)
    libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f5c5b9ce000)
    librt.so.1 => /usr/lib/librt.so.1 (0x00007f5c5b21b000)
    linux-vdso.so.1 (0x00007fffe27ff000)
~ $ ldd helloworld2 | sort
    libc.so.6 => /usr/lib/libc.so.6 (0x00007f7999497000)
    libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f799a60a000)
    libffi.so.6 => /usr/lib/libffi.so.6 (0x00007f799a1b4000)
    libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f7999ec0000)
    libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x00007f799a80e000)
    libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007f799a3bc000)
    libgthread-2.0.so.0 => /usr/lib/libgthread-2.0.so.0 (0x00007f7998f9b000)
    /lib/ld-linux-x86-64.so.2 (0x00007f799ac5d000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007f799919d000)
    libpango-1.0.so.0 => /usr/lib/libpango-1.0.so.0 (0x00007f799aa12000)
    libpcre.so.1 => /usr/lib/libpcre.so.1 (0x00007f7999a5a000)
    libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f799983e000)
    librt.so.1 => /usr/lib/librt.so.1 (0x00007f7999cb8000)
    linux-vdso.so.1 (0x00007fffa8fff000)

... it appears that the executables are dependant of exactly the same
.so files, just with different addresses. That means, the "--static"
flag doesn't make any difference when linking dynamic executables, and
it is required when linking static exe's. So, why doesn't pkg-config
simply assume that --static is always present, which would simplify some
things?

I would very much appreciate it if someone could explain me why the
--static flag exists, thank you in advance.
Niklas Gürtler
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/

iEYEARECAAYFAlBl4J8ACgkQfNJK65aYbI6gfwCgpeapqvfGVvfaaXav0yrKwCf5
UiMAoIj0WJ0lfE3UXfM+zP5g69gnyq3Z
=qqEq
-----END PGP SIGNATURE-----



More information about the pkg-config mailing list