Android/Termux build fails: oboe-sys requires -lc++_static due to incorrect cfg condition in tui/Cargo.toml

Open 💬 2 comments Opened May 26, 2026 by bash0816

Environment

  • Platform: Android (Termux) — aarch64
  • Rust target: aarch64-linux-android (native build on-device)
  • codex-rs version: 0.133.0

Error

error: linking with `clang` failed: exit status: 1
  = note: ld.lld: error: unable to find library -lc++_static

Root Cause

tui/Cargo.toml conditionally includes cpal as follows:

[target.'cfg(not(target_os = "linux"))'.dependencies]
cpal = "0.15"

On Android, Rust's target_os is "android" (not "linux"), so this condition evaluates to true and cpal gets pulled in. cpal → oboe → oboe-sys, and oboe-sys emits cargo:rustc-link-lib=static=c++_static for Android targets.

However, Termux does not provide libc++_static.a — only libc++_shared.so is available. The Android NDK static C++ runtime is not shipped with Termux.

Suggested Fix

Exclude Android from the cpal dependency, since audio is not needed for a CLI tool on Termux:

[target.'cfg(not(any(target_os = "linux", target_os = "android")))'.dependencies]
cpal = "0.15"

Alternatively, enable the oboe-shared-stdcxx feature on cpal for Android to use libc++_shared instead:

[target.'cfg(target_os = "android")'.dependencies]
cpal = { version = "0.15", features = ["oboe-shared-stdcxx"] }

Note: cpal exposes an oboe-shared-stdcxx feature that propagates shared-stdcxx to oboe-sys, switching the link from c++_static to c++_shared.

Workaround (used in current Termux builds)

Create a linker script shim:

mkdir -p ~/lib_shim
printf 'INPUT(-lc++_shared)\n' > ~/lib_shim/libc++_static.a

Add to RUSTFLAGS:

-C link-arg=-L/path/to/lib_shim -C link-arg=-L/usr/lib

Additional Context

This was discovered while building codex-rs natively on Android/Termux for @bash0816/codex-termux, a community Termux wrapper for Codex.

View original on GitHub ↗

2 Comments

lurenjia534 · 3 months ago

I looked into this and confirmed the dependency path.

codex-tui currently includes cpal on Android because Android matches:

[target.'cfg(not(target_os = "linux"))'.dependencies]
cpal = "0.15"

That pulls in cpal -> oboe -> oboe-sys. On Android, oboe-sys links
c++_static, which is the source of the Termux build failure.

A minimal fix would be to treat Android like Linux for local realtime audio
support:

[target.'cfg(not(any(target_os = "linux", target_os = "android")))'.dependencies]
cpal = "0.15"

The matching Rust cfg gates should also use the existing Linux
stub/no-local-audio path on Android.

I validated the dependency side locally:

cargo tree --offline -p codex-tui --target aarch64-linux-android -i cpal
# warning: nothing to print.

cargo tree --offline -p codex-tui --target aarch64-linux-android -i oboe-sys
# warning: nothing to print.

I also verified a local patch with:

cargo check -p codex-tui
just fix -p codex-tui
just bazel-lock-update
just bazel-lock-check

I have a small focused local patch for this and would be happy to submit a PR if
the Codex team is open to an invited external PR for this issue.

bash0816 · 3 months ago

Thanks for the detailed investigation! Please go ahead and submit the PR — the fix looks correct.