2.99 meson build fails to link to libexecinfo on Alpine Linux
link error, "undefined symbol: backtrace", etc.
Install Alpine linux and its package libexecinfo-dev.
Build GIMP using meson.
Expect build to complete, actual is link error as described.
On most platforms, backtrace() is part of libc and is an "internal to the compiler" library. (Note there is another libbacktrace; it does not provide the backtrace() symbol.)
On some platforms e.g. Alpine, which uses musl instead of libc, backtrace is in a library libexecinfo. Also OpenBSD might be a case, but not FreeBSD or NetBSD?
There are two files that have code similar to this:
#if defined(G_OS_UNIX) && defined(HAVE_EXECINFO_H) #include <execinfo.h>
The two files are:
The include that is in app/core/gimp-utils.c is apparently cruft, there is no code that refers to definitions from execinfo.h, and gimp-utils.c compiles fine without that include. So part of the fix is to delete those lines of code from app/core/gimp-utils.c
Another part of the fix is to /libgimpbase/meson.build:
diff --git a/libgimpbase/meson.build b/libgimpbase/meson.build index a688785df2..83b08902ed 100644 --- a/libgimpbase/meson.build +++ b/libgimpbase/meson.build @@ -100,12 +100,13 @@ libgimpbase_introspectable = [ libgimpbase_headers_introspectable, ] +optional_libexecinfo = cc.find_library('execinfo', required: false) libgimpbase = library('gimpbase-' + gimp_api_version, libgimpbase_sources, include_directories: rootInclude, dependencies: [ - gexiv2, gio, math, + gexiv2, gio, math, optional_libexecinfo ], c_args: [ '-DG_LOG_DOMAIN="LibGimpBase"',
Since I am relatively new to meson and GIMP, I will explain the fix. In gimp/meson.build it checks for the header execinfo.h and sets the compile flag HAVE_EXECINFO_H. In libgimpbase/gimputil.c, the code that calls backtrace() is conditionally compiled on HAVE_EXECINFO.H. In the fix, "optional_libexecinfo = cc.find_library('execinfo', required: false)" creates a dependency object. The target library depends on it, so meson will link to the library if the dependency is found (on Alpine) otherwise it will ignore it (on Ubuntu etc.)
I tested that:
the fix does not break a Linux build (Ubuntu 21.04) fixes an Alpine build,
but I am not sure that the fix doesn't break other platform builds.
I didn't actually test that the code that calls backtrace() works, since it is fallback when gdb is not installed.