首页 > 解决方案 > WebRTC: Undefined reference to "__real_malloc" in Android project linking with WebRTC library

问题描述

My project is an NDK-based Android shared library that links in Chromium's WebRTC shared library. When linking my project's native code component, I see some "undefined reference" errors, but they are for symbols that should be generated by the linker itself:

    __real_malloc, et. al.
    __executable_start

The undefined references stem from WebRTC object files:

base/allocator/allocator_shim_default_dispatch_to_linker_wrapped_symbols.cc:39: undefined reference to `__real_malloc'
base/trace_event/trace_log.cc:1615: undefined reference to `__executable_start'

My question: Why are these symbols undefined? How can I fix it? These are the only errors reported. There are no other errors or warnings.

I look forward to any insights from the community. I've been stuck on this for a long time! I'm new to Android development and probably doing something basic wrong.

Thanks!

Additional background information, in case it's helpful.

WebRTC build environment:

My own project build environment:

I build my project using a Gradle+CMake configuration generated by Android Studio. First I have to build Chromium's WebRTC library using their Ninja-based build system (called Depot Tools). Once that succeeds, I create a static library for the WebRTC component using a bash script:

    # Get the names of all the object files.
    find ./obj -name *.o >libwebrtc.list
    # Generate the static library.
    cat libwebrtc.list | xargs ar -crs libwebrtc.a
    # Add an index to the static library.
    ranlib libwebrtc.a

Now I have a static library with WebRTC symbols I can link into my project (my project is itself a shared library). As an aside, I wonder if there's an "official" way to build this static WebRTC library. I couldn't find any mention of it.

Next, I compile and link my project using the NDK's externalNativeBuild to call my CMakeLists.txt script. It compiles everything with no warnings, but the linker fails to find a the symbols mentioned above.

标签: androidandroid-ndkwebrtc

解决方案


我解决了我自己的问题。供将来参考:Chromium WebRTC 构建实际上创建了自己的 libwebrtc.a 静态库。我不需要自己做。当我引用 libwebrtc.a 的“官方”版本时,一切都成功链接。


推荐阅读