You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Android NDK r17编译FFmpeg时遇__mulodi4未定义引用问题

Fixing FFmpeg Compilation & Integration Issues with NDK r17 and Clang

Let's break down your two linked issues and fix them step by step:

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 running make_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-toolchain
    
  • Adjust FFmpeg configure flags to link the correct runtime
    Update your FFmpeg configure command 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 -L flag pointing to the correct library directory for your API level, followed by -lclang_rt.builtins-i686-android to link the runtime.

  • Verify you're not overriding critical linker flags
    Check if any custom LDFLAGS in 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 your build.gradle to 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++_shared
    
  • Ensure 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:25:33