Add explicit libm linkage to fix undefined symbol errors#1305
Open
veeceey wants to merge 1 commit intoMagicStack:masterfrom
Open
Add explicit libm linkage to fix undefined symbol errors#1305veeceey wants to merge 1 commit intoMagicStack:masterfrom
veeceey wants to merge 1 commit intoMagicStack:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
-lmlinkage to fix undefined symbol errors on certain build environmentslog10()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:
This happens because the C extensions use math functions from
libmbut don't explicitly link against it. On some modern toolchains (particularly Clang-based ones),libmis not implicitly linked, causing runtime symbol resolution failures even though compilation succeeds.Running
lddon the affected.sofiles shows they are missing thelibm.sodependency:linux-vdso.so.1 (0x0000ffff9e066000) libc.so.6 => /lib64/libc.so.6 (0x0000ffff9ddce000) /lib/ld-linux-aarch64.so.1 (0x0000ffff9e019000) undefined symbol: log10Changes
setup.pyto add-lmtoLDFLAGSon non-Windows systemsTest plan
The fix is minimal and follows standard C extension build practices. The
-lmflag is commonly used in C extension modules that use math functions and is recognized by all major compilers (GCC, Clang, etc.).