makefile - 对 '_Unwind_GetIP' 的 undefined reference

标签 makefile android-ndk linker rust cross-compiling

我在获取 rustc 时遇到了一些麻烦编译staticlib对于三重,arm-linux-androideabi , 在 Android Studio 中很好地链接。

采取的步骤...

  1. 通过 multirust 安装 Rust
  2. 为 Android API v14 构建 rustc
  3. 使用 --target=arm-linux-androideabi 构建库
  4. 添加到 jniLibs/在 Android Studio 中
  5. 为 JNI 的钩子(Hook)创建一个小的 C++ shim
  6. 构建和链接(几乎)

构建我的箱子时,我得到以下输出:

note: link against the following native artifacts when linking 
      against this static library
note: the order and any duplication can be significant on some platforms, 
      and so may need to be preserved
note: library: c
note: library: m
note: library: dl
note: library: log
note: library: gcc
note: library: c
note: library: m

很自然地,我的 Android.mk 在使用静态库时包含这些库。

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := hydrogen
LOCAL_SRC_FILES := ../jniLibs/$(TARGET_ARCH_ABI)/libhydrogen.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := hydrogen-android
LOCAL_SRC_FILES := shim.cpp
LOCAL_STATIC_LIBRARIES := hydrogen
LOCAL_LDLIBS := -lc -lm -ldl -llog -lgcc -lc -lm
include $(BUILD_SHARED_LIBRARY)

在 Android Studio 中构建会得到以下输出:

:app:buildCppShim
Android NDK: WARNING:/Android.mk:hydrogen: non-system libraries in linker flags: -lgcc -lgccunwind    
Android NDK:     This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES    
Android NDK:     or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the    
Android NDK:     current module    

[armeabi] Compile++ thumb: hydrogen-android <= shim.cpp
[armeabi] SharedLibrary  : libhydrogen-android.so
[snipped]function sync::rwlock::StaticRwLock::read::ha5ec9717ccd1ed83Lxp: error: undefined reference to 'pthread_rwlock_rdlock'
[snipped]function sys_common::rwlock::RWLock::read::h7f3d472c79e2e1e2Z1q: error: undefined reference to 'pthread_rwlock_rdlock'
[snipped]function sys_common::rwlock::RWLock::read_unlock::hd7d67e9c5c47b9f5B2q: error: undefined reference to 'pthread_rwlock_unlock'
[snipped]function sync::rwlock::StaticRwLock::try_read::hddd396186cced62f8xp: error: undefined reference to 'pthread_rwlock_tryrdlock'
[snipped]function sys_common::rwlock::RWLock::try_read::ha5aede723e91a3c881q: error: undefined reference to 'pthread_rwlock_tryrdlock'
[snipped]function sync::rwlock::StaticRwLock::write::h787666bb30e75d28Ryp: error: undefined reference to 'pthread_rwlock_wrlock'
[snipped]function sys_common::rwlock::RWLock::write::h0273da9a7ade68c0i2q: error: undefined reference to 'pthread_rwlock_wrlock'
[snipped]function sync..rwlock..RwLockWriteGuard$LT$$LP$$RP$$GT$::drop.34348::h4c8fbe45843b9a01: error: undefined reference to 'pthread_rwlock_unlock'
[snipped]function sync::rwlock::StaticRwLock::try_write::h5d30a7fdd53c86b4ezp: error: undefined reference to 'pthread_rwlock_trywrlock'
[snipped]function sys_common::rwlock::RWLock::try_write::h0ec4bcc0cb460718r2q: error: undefined reference to 'pthread_rwlock_trywrlock'
[snipped]function sync::rwlock::StaticRwLock::destroy::ha1e9f51e62905aedXzp: error: undefined reference to 'pthread_rwlock_destroy'
[snipped]function sys_common::rwlock::RWLock::destroy::h602ce773ff2356e6T2q: error: undefined reference to 'pthread_rwlock_destroy'
[snipped]function sys::rwlock::RWLock::read::h241f5fdff06a76ab00u: error: undefined reference to 'pthread_rwlock_rdlock'
[snipped]function sys::rwlock::RWLock::write::h48034b52e6491ea4h3u: error: undefined reference to 'pthread_rwlock_wrlock'

~/bin/rust/src/compiler-rt/lib/builtins/gcc_personality_v0.c
Error:(206) undefined reference to '_Unwind_GetIP'
Error:(273) undefined reference to '_Unwind_SetGR'
Error:(274) undefined reference to '_Unwind_SetGR'
Error:(275) undefined reference to '_Unwind_SetIP'

线程错误 我不确定为什么会收到有关 pthread 的错误,因为我有 #include <pthread.h>在我的 shim 中,这些函数在 Android's pthread 中定义.

展开错误 为此,我尝试包括 unwind.h在垫片和libgccunwind.aAndroid.mk ,但仍然会抛出相同的错误。我找到了 this thread黑客解决方案是在垫片中声明原型(prototype),但是当我这样做时,我收到以下关于 unwind.h 的错误

Error:(231, 3) error: previous declaration 'void _Unwind_SetGR(_Unwind_Context*, int, _Unwind_Word)' here

所以,当我声明它们时它能够找到它们的声明,因为它们有冲突,但如果我不声明它们就不知道它们在哪里?我假设我的链接顺序一定有问题,但不确定如何解决它,因为在拉入使用rust 创建的库后,所需的库被链接。

如有任何帮助,我们将不胜感激!

编辑 1 在共享库创建过程中将 makefile 调整为链接。

最佳答案

LOCAL_LDLIBS 对于静态库没有意义(静态库不被链接)。每当您在真正的二进制文件(如共享库或可执行文件)中使用该库时,您都需要添加这些库。

关于makefile - 对 '_Unwind_GetIP' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31932902/

相关文章:

c - 如何将 C 文件编译成可执行 (.exe) 文件?

c++ - 检查 Makefile 中使用的 g++ 版本

linux - 如何在 makefile 中包含 .h 文件

android - 在 Android 手机上编译 C 代码

gradle - 使用 CMAKE : no dynamic library found error 构建 NDK 可执行文件

Android C++ framebuffer ioctl,只有 root?

lua - ld : warning: ignoring file liblua. a,为 macOS-x86_64 构建,但尝试链接为未知不支持的文件格式构建的文件(0x21 0x3C

linux - 便利库中的符号未在可执行文件中导出

python - 当 requirements.txt 或 setup.py 改变时用 tox 重新安装 virtualenv

c - 静态库和 JNI