使用Android NDK r17编译FFmpeg时遇__mulodi4未定义引用问题
Let's break down your two linked issues and fix them step by step:
1. Resolving undefined reference to '__mulodi4' Link Errors
The __mulodi4 function is a Clang runtime utility for integer multiplication, and this error pops up because the linker isn't finding the right compiler runtime library (NDK r17 replaced the old libgcc with libcompiler_rt). Your attempt to link libclang_rt.builtins-i686-android.a was on the right track, but likely failed due to incorrect pathing or link order. Try these fixes:
Ensure your standalone toolchain was generated correctly
When runningmake_standalone_toolchain.py, specify a valid API level (minimum 21 for x86 with modern Clang) and confirm the toolchain path:make_standalone_toolchain.py --arch x86 --api 21 --install-dir ./x86-ndk-toolchainAdjust FFmpeg configure flags to link the correct runtime
Update your FFmpegconfigurecommand to explicitly point to the toolchain's sysroot and link the compiler runtime library in the right order (libraries must come after the objects that reference them):./configure \ --cross-prefix=x86-ndk-toolchain/bin/i686-linux-android- \ --sysroot=x86-ndk-toolchain/sysroot \ --target-os=android \ --arch=x86 \ --enable-cross-compile \ --extra-cflags="-march=i686 -O2" \ --extra-ldflags="-Lx86-ndk-toolchain/sysroot/usr/lib/i686-linux-android/21 -lclang_rt.builtins-i686-android"The key here is the
-Lflag pointing to the correct library directory for your API level, followed by-lclang_rt.builtins-i686-androidto link the runtime.Verify you're not overriding critical linker flags
Check if any customLDFLAGSin your build script are stripping out or overriding the runtime library links—this is a common gotcha.
2. Fixing __asan Undefined References in Your Test AAR
When you compile FFmpeg with AddressSanitizer (ASAN), the entire project that uses this FFmpeg build must also enable ASAN. The errors happen because your test AAR isn't linked against the ASAN runtime. Here's how to fix it:
Enable ASAN in your test AAR's build configuration
If you're using CMake in your Android project, update yourbuild.gradleto enable ASAN and use the shared STL (required for ASAN):android { defaultConfig { minSdkVersion 21 // ASAN requires API 21+ externalNativeBuild { cmake { arguments "-DANDROID_STL=c++_shared", "-DANDROID_ADDRESS_SANITIZER=on" } } } }For ndk-build, add these lines to your
Android.mk:LOCAL_CFLAGS += -fsanitize=address LOCAL_LDFLAGS += -fsanitize=address LOCAL_STL := c++_sharedEnsure consistent NDK versions
Make sure your test AAR project uses the same NDK r17 version as your FFmpeg build—mismatched NDK versions can cause runtime library conflicts.Clean and rebuild everything
ASAN builds can leave stale artifacts, so do a full clean of both your FFmpeg build directory and your Android project before rebuilding.
内容的提问来源于stack exchange,提问作者fpsulli3

