Cross-compiling glib (without desktop): overcomplicated

I need static libs of glib to build BlueZ which my application is using.

Everything is CLI only.

I need to cross-compile everything to create a smooth coherent environment.

So I need to cross-compile glib, but it’s way too complicated.

1.) Got the source from gitlab (latest master)
2.) Created cross.txt:
For BlueZ to be successfully cross-compiled, we need to have the glib library (even in configure time).

glib itself is a beast, containing massive amount of unnecessary code.

We are building on CLI (no desktop), and target is also CLI-only.

Now glib build fails, gio-desktop failed to build.

Is there a way to cross-compile this glib library without desktop functionality?

Update

glib’s source has been obtained from their repository:

https://gitlab.gnome.org/GNOME/glib

cross.txt:

[binaries]
c = '/opt/x-tools/aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc'
cpp = '/opt/x-tools/aarch64-linux-gnu/bin/aarch64-linux-gnu-g++'
ar = '/opt/x-tools/aarch64-linux-gnu/bin/aarch64-linux-gnu-ar'
strip = '/opt/x-tools/aarch64-linux-gnu/bin/aarch64-linux-gnu-strip'

[host_machine]
system = 'Linux'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'

[built-in options]
c_args = ['-O3', '-flto=auto', '-funroll-loops', '-fno-plt']
cpp_args = ['-O3', '-flto=auto', '-funroll-loops', '-fno-plt']
  1. Meson setup:
meson setup ~/src/lib/glib . 
  --cross-file ./cross.txt  
  --prefix=staging 
  --default-library=static 
  -Dintrospection=disabled  
  -Dtests=false
  1. Build fail!
ninja
...
[278/705] Linking target gio/gio-launch-desktop
FAILED: gio/gio-launch-desktop
gio-launch-desktop.c:199:(.text.startup+0x58): undefined
 reference to `_g_fd_is_journal'
collect2: error: ld returned 1 exit status
...
[285/705] Linking target glib/gtester
FAILED: glib/gtester
/gmessages.c:2117:(.text+0x6a98): undefined reference to `_g_fd_is_journal'
collect2: error: ld returned 1 exit status
...
[286/705] Linking target gobject/gobject-query
FAILED: gobject/gobject-query
gmessages.c:2117:(.text+0x6818): undefined reference to `_g_fd_is_journal'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

To be honest, I need only glib, nothing else.

I could build successfully with “ninja -C builddir glib/libglib-2.0.so gobject/libgobject-2.0.so gio/libgio-2.0.so”

But then it’s again way too overcomplicated to copy everything to proper destination in “staging” directery: libraries, headers, pkgconfig script.

Oh, and in this successul build case, if I call “ninja install”, it will try to build those failing targets, and eventually fail.

Anyone?

It looks like gjournal-private.c is only compiled if host_system == 'linux'. Can you investigate why gio/meson.build skips its addition perhaps?

Is it case sensitive? I believe mine is set to “Linux”.

Although I’m not with my computer at the moment.

Thank you!

I’m not familiar enough with Meson to know off-hand. However it happens, that file needs to be compiled at least for this to work as expected. Making the build not assume that looks more complicated.

Ok, thank you! Will try and report back.

Jusr have it tested:

host_system == 'linux' was the issue. Mine was set to Linux.

Changing it to lowercase solved the build issue.

Thank you!