glibmeson-build

How to do static linking of a specific library in meson?


I am trying to build glib, which I downloaded from Github. However, library libpcre2 is dynamically linked

epatrek@seliiuts03047[12:12][babeltrace/glib/glib-2.76.5]$ ldd _build/glib/libglib-2.0.so.0
linux-vdso.so.1 =>  (0x00007ffd79111000)
librt.so.1 => /lib64/librt.so.1 (0x00007f3402e28000)
libpcre2-8.so.0 => /proj/wcdmaiov/epatrek/babeltrace/glib/pcre2-10.42-bin/lib/libpcre2-8.so.0 (0x00007f3402bb0000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3402993000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3402617000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3403373000)

I would want to link it statically while keeping all the other dependencies dynamic. I have tried a few things without success (commenting out faulty lines in traditional developer sloppiness),

meson setup --prefix /proj/wcdmaiov/epatrek/babeltrace/glib/glib-2.76.5-install _build
#env LDFLAGS="-Wl,-Bstatic -llibpcre2-8.a" meson setup --prefix /proj/wcdmaiov/epatrek/babeltrace/glib/glib-2.76.5-install _build
#meson setup --prefix /proj/wcdmaiov/epatrek/babeltrace/glib/glib-2.76.5-install _build -Dlibpcre:libtype=static
#meson setup --prefer-static --prefix /proj/wcdmaiov/epatrek/babeltrace/glib/glib-2.76.5-install _build
meson compile -C _build
meson install -C _build

But all the approaches either causes the build to fail or does not do what I expect. The --prefer-static is for example trying to link all the libraries as static (which I assume is correct, but not what I want to do), which causes some problems with libc and other libs not compiled with -fPIC.

Anyone who knows how this can be done? If possible I would want to avoid patching the meson.build.

BR Patrik


Solution

  • Take a look at the meson.build section for finding pcre2. It looks like pcre2 will be linked dynamically if it is found in the system, and statically if it is built as a Meson subproject. I think you can force the use of a subproject with meson setup --force-fallback-for libpcre2-8.