android - 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:
- Ubuntu 18.04
- Toolchain: NDK r13/clang/llvm (installed via Depot Tools)
- Cross-compile for Android
My own project build environment:
- Windows 10
- Toolchain: NDK r19/clang/llvm
- Cross-compile for Android
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.
解决方案
我解决了我自己的问题。供将来参考:Chromium WebRTC 构建实际上创建了自己的 libwebrtc.a 静态库。我不需要自己做。当我引用 libwebrtc.a 的“官方”版本时,一切都成功链接。
推荐阅读
- java - 从多个线程向 SoftAssertions 添加失败
- python - 使用 Xarray 从 netCDF 文件中提取数据到高 DataFrame 的有效方法
- java - 每次创建新实例时,ArrayList 都会被覆盖
- javascript - 如何将 2D 实时动态文本添加到 Three.js 场景?
- javascript - React - 并排显示图像
- python - 如何打印与两个不同列表中的不同值相对应的值?(Python)
- reactjs - 如何在 setState 之后 localStorage 设置项目?
- html - translateY(-50%)后如何调整父div的高度
- c - c中可变大小的数组
- java - 如何将 Java 文件添加到构建路径 Android Studio