对“_Unwind_GetIP”的未定义引用
Undefined reference to '_Unwind_GetIP'
我在 rustc
为三重 arm-linux-androideabi
编译 staticlib
到 link 在 Android Studio 中很好地编译时遇到了一些麻烦.
采取的步骤...
- 通过 multirust
安装 Rust
- 为 Android API v14
构建一个 rustc
- 使用
--target=arm-linux-androideabi
构建库
- 在 Android Studio
中添加到 jniLibs/
- 为钩子创建一个小的 C++ shim to/from JNI
- 构建和link(几乎)
构建我的 crate 时,我得到以下输出:
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 的错误,因为我的 shim 中有 #include <pthread.h>
,并且这些函数在 Android's pthread
.
中定义
展开错误
为此,我尝试在 shim 中包含 unwind.h
并在 Android.mk
中包含 libgccunwind.a
,但仍然会抛出相同的错误。我发现 this thread 黑客解决方案是在 shim 中声明原型,但是当我这样做时,我收到以下关于 unwind.h
的错误
Error:(231, 3) error: previous declaration 'void _Unwind_SetGR(_Unwind_Context*, int, _Unwind_Word)' here
所以,当我声明它们时它能够找到它们的声明,因为它们冲突,但如果我不声明它们就不知道它们在哪里?我假设我的 linking 命令一定有问题,但不确定如何解决它,因为在拉入生锈创建的库后,所需的库被 linked 反对。
如有任何帮助,我们将不胜感激!
编辑 1
在创建共享库期间将 makefile 调整为 link。
LOCAL_LDLIBS 对于静态库没有意义(静态库不链接)。每当您在真正的二进制文件(如共享库或可执行文件)中使用该库时,您都需要添加这些库。
解决方案恰好是构建 unwind 并包括一些可移植性 headers。请参阅模块示例 here
我在 rustc
为三重 arm-linux-androideabi
编译 staticlib
到 link 在 Android Studio 中很好地编译时遇到了一些麻烦.
采取的步骤...
- 通过 multirust 安装 Rust
- 为 Android API v14 构建一个 rustc
- 使用
--target=arm-linux-androideabi
构建库
- 在 Android Studio 中添加到
- 为钩子创建一个小的 C++ shim to/from JNI
- 构建和link(几乎)
jniLibs/
构建我的 crate 时,我得到以下输出:
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 的错误,因为我的 shim 中有 #include <pthread.h>
,并且这些函数在 Android's pthread
.
展开错误
为此,我尝试在 shim 中包含 unwind.h
并在 Android.mk
中包含 libgccunwind.a
,但仍然会抛出相同的错误。我发现 this thread 黑客解决方案是在 shim 中声明原型,但是当我这样做时,我收到以下关于 unwind.h
Error:(231, 3) error: previous declaration 'void _Unwind_SetGR(_Unwind_Context*, int, _Unwind_Word)' here
所以,当我声明它们时它能够找到它们的声明,因为它们冲突,但如果我不声明它们就不知道它们在哪里?我假设我的 linking 命令一定有问题,但不确定如何解决它,因为在拉入生锈创建的库后,所需的库被 linked 反对。
如有任何帮助,我们将不胜感激!
编辑 1 在创建共享库期间将 makefile 调整为 link。
LOCAL_LDLIBS 对于静态库没有意义(静态库不链接)。每当您在真正的二进制文件(如共享库或可执行文件)中使用该库时,您都需要添加这些库。
解决方案恰好是构建 unwind 并包括一些可移植性 headers。请参阅模块示例 here