Skip to content

Add explicit libm linkage to fix undefined symbol errors#1305

Open
veeceey wants to merge 1 commit intoMagicStack:masterfrom
veeceey:fix/issue-1297-missing-libm-linkage
Open

Add explicit libm linkage to fix undefined symbol errors#1305
veeceey wants to merge 1 commit intoMagicStack:masterfrom
veeceey:fix/issue-1297-missing-libm-linkage

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

  • Adds explicit -lm linkage to fix undefined symbol errors on certain build environments
  • Resolves runtime symbol resolution failures for math functions like log10()
  • Only affects non-Windows platforms

Issue

Fixes #1297

When building asyncpg on certain platforms (e.g., Amazon Linux 2023 with Clang 20), the compiled C extensions fail to load at runtime with errors like:

undefined symbol: log10 (./lib/python3.12/site-packages/asyncpg/pgproto/pgproto.cpython-312-aarch64-linux-gnu.so)

This happens because the C extensions use math functions from libm but don't explicitly link against it. On some modern toolchains (particularly Clang-based ones), libm is not implicitly linked, causing runtime symbol resolution failures even though compilation succeeds.

Running ldd on the affected .so files shows they are missing the libm.so dependency:

linux-vdso.so.1 (0x0000ffff9e066000)
libc.so.6 => /lib64/libc.so.6 (0x0000ffff9ddce000)
/lib/ld-linux-aarch64.so.1 (0x0000ffff9e019000)
undefined symbol: log10

Changes

  • Modified setup.py to add -lm to LDFLAGS on non-Windows systems
  • This ensures proper linkage with the math library for all C extensions

Test plan

  • Builds successfully on systems where libm was previously missing
  • No impact on platforms where libm was already linked implicitly
  • Windows builds unaffected (libm not applicable on Windows)

The fix is minimal and follows standard C extension build practices. The -lm flag is commonly used in C extension modules that use math functions and is recognized by all major compilers (GCC, Clang, etc.).

When building asyncpg on certain platforms (e.g., Amazon Linux 2023
with Clang 20), the C extensions fail to load at runtime with errors
like "undefined symbol: log10". This happens because the extensions
use math functions from libm but don't explicitly link against it.

On some toolchains, libm is not implicitly linked, causing runtime
symbol resolution failures even though compilation succeeds.

This fix adds `-lm` to LDFLAGS on non-Windows systems to ensure
proper linkage with the math library.

Fixes MagicStack#1297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing libm linkage causes undefined symbol errors

1 participant