Skip to content

Android (Bionic) cross-compilation fails: bzero macro conflict + missing dlinfo #106

@hoppete

Description

@hoppete

Summary

cb-mpc does not compile for Android ARM64 (NDK r28, Bionic libc) due to two issues:

  1. bzero macro conflict — Android Bionic defines bzero as a macro in <strings.h>. This conflicts with coinbase::bzero() in include/cbmpc/core/buf.h, causing parse errors throughout the codebase.

  2. dlinfo / RTLD_DI_LINKMAP unavailablesrc/cbmpc/core/error.cpp uses these inside #ifdef __linux__, but Android defines __linux__ without providing dlinfo (glibc extension, not in Bionic).

  3. cmake/openssl.cmake platform check — The link_openssl macro only handles IS_LINUX and IS_MACOS, skipping iOS and Android with "unsupported platform".

Environment

  • cb-mpc: v0.2.1 (commit from main branch)
  • NDK: r28 (28.0.13004108)
  • Target: arm64-v8a, Android API 24
  • Host: macOS ARM64
  • OpenSSL: 3.6.1 cross-compiled for android-arm64

Suggested Fix

Three small, non-breaking changes:

1. include/cbmpc/core/buf.h — undef Bionic's bzero macro

 #include <cbmpc/core/macros.h>
 
+// Android Bionic defines bzero as a macro, which conflicts with coinbase::bzero.
+#ifdef bzero
+#undef bzero
+#endif
+
 namespace coinbase {

2. src/cbmpc/core/error.cpp — guard glibc-only APIs

-#ifdef __linux__
+#if defined(__linux__) && !defined(__ANDROID__)
 class symbols_t {

Same change on two more #ifdef __linux__ blocks in the same file (lines ~229 and ~247) that reference symbols_t.

3. cmake/openssl.cmake — add mobile platforms

-  elseif(IS_MACOS)
+  elseif(IS_MACOS OR IS_IOS OR IS_IOS_SIMULATOR OR IS_ANDROID)

The lib path layout (${CBMPC_OPENSSL_ROOT}/lib/libcrypto.a) is the same across all Apple and Android targets.

Result

With these patches applied:

  • Android ARM64 (arm64-v8a): builds successfully, libcbmpc.a 4.1MB stripped (ELF64 AArch64)
  • iOS ARM64: builds successfully, libcbmpc.a 5.0MB (Mach-O arm64, platform iOS, min 15.0)
  • macOS ARM64: no change, existing build unaffected

Note: compilation_flags.cmake already has Android-specific linker flags (lines 72-77), suggesting Android support was partially considered but never completed.

Context

We're building a Flutter app that uses cb-mpc via dart:ffi (mobile) and Go CGO (backend). macOS builds work perfectly (validated in our PoC). iOS builds work with just the cmake platform patch. Android needs all three fixes.

Happy to submit a PR if you're open to it. The changes are minimal and don't affect existing Linux/macOS builds.

Related: #67 (iOS support question)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions