Building mpg123 using non-legacy CMake toolchain fails
Brought to you by:
sobukus
When using the non-legacy CMake toolchain, linking mpg123 fails with the following error:
ld.lld: error: relocation R_386_GOTOFF cannot be used against symbol 'INT123_costab_mmxsse'; recompile with -fPIC
>>> defined in src/libmpg123/CMakeFiles/libmpg123.dir/home/maarten/programming/mpg123-github-official-fork/src/libmpg123/tabinit_mmx.S.o
>>> referenced by dct64_sse_float.S:83 (/home/maarten/programming/mpg123-github-official-fork/src/libmpg123/dct64_sse_float.S:83)
>>> src/libmpg123/CMakeFiles/libmpg123.dir/home/maarten/programming/mpg123-github-official-fork/src/libmpg123/dct64_sse_float.S.o:(.text+0x7B)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Reproducer:
cmake -S ~/projects/mpg123/ports/cmake -B mpg123-android-x86 -GNinja -DCMAKE_TOOLCHAIN_FILE=$HOME/Android/Sdk/ndk/28.2.13676358/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86 -DANDROID_PLATFORM=android-26 -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF -DBUILD_PROGRAMS=OFF -DBUILD_LIBOUT123=OFF -DBUILD_SHARED_LIBS=ON --fresh
cmake --build mpg123-android-x86 --target libmpg123
The following patch fixes the problem (for me):
--- a/src/libmpg123/mangle.h
+++ b/src/libmpg123/mangle.h
@@ -139,7 +139,7 @@ Lpic_base: \
#endif /* PIC variants */
// Apple and Android NDK seem both not to like direct global access.
-#if defined(PIC) && (defined(__APPLE__) || defined(ANDROID))
+#if defined(PIC) && (defined(__APPLE__) || defined(__ANDROID__))
#define PIC_GLOBAL_PTR
#endif
diff --git a/src/libmpg123/tabinit_mmx.S b/src/libmpg123/tabinit_mmx.S
index 077e19e7..332bcd22 100644
Unrelated to the error, but would this patch make sense?
Am Wed, 10 Sep 2025 14:19:19 -0000
schrieb "Maarten" pacha2087@users.sourceforge.net:
Yeah … I guess we probably should define a macro
and use that everywhere?
Am Wed, 10 Sep 2025 14:18:39 -0000
schrieb "Maarten" pacha2087@users.sourceforge.net:
So our resolution of bug #345 was fauly in putting ANDROID in there? Or
rather, this used to be defined and now only ANDROID is?
You suggested using
__ANDROID__there.__ANDROID__is a built-in macro, whereasANDROIDis added by the CMake toolchain file.Reading the verbose build log,
-DANDROIDis correctly passed when compiling C sources, but not when assembling S sources.Last edit: Maarten 2025-09-12
How's the current trunk for both?
Trunk works :)