Building statically linked binaries of a program depending on h-gpgme

I’d like to build a statically linked binary of a program using the h-gpgme package. I am using various alpine linux containers having ghc/cabal builtin or using ghcup to setup the ghc/cabal environment. Invariably, the process fails in the linking phase with undefined refrences, here is a segment of the error messages:

'ghc' version < 9.12): /usr/local/bin/ghc is version 9.12.1
Resolving dependencies...
Build profile: -w ghc-9.12.1 -O1
In order, the following will be built (use -v for more details):
 - static-gpgme-0.1.0.0 (exe:static-gpgme) (first run)
Configuring executable 'static-gpgme' for static-gpgme-0.1.0.0...
Preprocessing executable 'static-gpgme' for static-gpgme-0.1.0.0...
Building executable 'static-gpgme' for static-gpgme-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, dist-newstyle/build/x86_64-linux/ghc-9.12.1/static-gpgme-0.1.0.0/x/static-gpgme/build/static-gpgme/static-gpgme-tmp/Main.o )
[2 of 2] Linking dist-newstyle/build/x86_64-linux/ghc-9.12.1/static-gpgme-0.1.0.0/x/static-gpgme/build/static-gpgme/static-gpgme
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../lib/libgpgme.a(data.o): in function `gpg_error_from_syserror':
data.c:(.text+0x92): undefined reference to `gpg_err_code_from_syserror'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../lib/libgpgme.a(data.o): in function `_gpgme_data_get_dserial':
data.c:(.text+0x1a8): undefined reference to `gpgrt_lock_lock'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: data.c:(.text+0x229): undefined reference to `gpgrt_lock_unlock'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../lib/libgpgme.a(data.o): in function `_gpgme_data_set_prop':
data.c:(.text+0x29d): undefined reference to `gpgrt_lock_lock'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: data.c:(.text+0x3a7): undefined reference to `gpgrt_lock_unlock'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../lib/libgpgme.a(data.o): in function `_gpgme_data_get_prop':
data.c:(.text+0x438): undefined reference to `gpgrt_lock_lock'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: data.c:(.text+0x534): undefined reference to `gpgrt_lock_unlock'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld.bfd: /usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../lib/libgpgme.a(data.o): in function `_gpgme_data_new':
data.c:(.text+0x5bd): undefined reference to `gpgrt_lock_lock'

I can build the binary when the external dependencies dinamically linked. Here is the ldd output of the linked external libs:

    /lib/ld-musl-x86_64.so.1 (0x70199e97c000)
    libgpgme.so.11 => /usr/lib/libgpgme.so.11 (0x70199e932000)
    libgmp.so.10 => /usr/lib/libgmp.so.10 (0x70199e8c8000)
    libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x70199e97c000)
    libassuan.so.0 => /usr/lib/libassuan.so.0 (0x70199e8b7000)
    libgpg-error.so.0 => /usr/lib/libgpg-error.so.0 (0x70199e896000)

All the static and development versions of the external dependencies are installed but using cabal build --enable-executable-static fails as shown above. In fact, I can even manually find the references in the corresponding static libraries.

I can build statically linked binaries if there are no dependency packages using FFI to wrap external libraries. However when such package is involved the linking fails.

Is there some special detail what I am overlooking? Any advice would be appreciated.

Here is a small sample using h-gpgme :

import Crypto.Gpgme
import Data.ByteString qualified as BS
import Data.ByteString.UTF8 qualified as BSU
import System.Environment

-- ...

decryptLib :: String -> IO String
decryptLib fname = do
  gpgHome <- getEnv "HOME" >>= \x -> pure (x ++ "/.gnupg")
  enc <- BS.readFile fname
  withCtx gpgHome "C" OpenPGP $ \ctx ->
    decrypt ctx enc
      >>= \case
        Left err -> error $ "decryptLib error:\n" ++ show err
        Right dec -> return $ BSU.toString dec