我在使用rustc
编译staticlib
三重arm-linux-androideabi
时遇到了一些麻烦,以便在Android Studio中很好地进行链接。
采取的步骤......
--target=arm-linux-androideabi
jniLibs/
在构建我的箱子时,我得到以下输出:
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在使用staticlib时包含了这些库。
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错误
我不确定为什么我收到有关pthread的错误,因为我的垫片中有#include <pthread.h>
,这些函数在Android's pthread
中定义。
展开错误
为此,我尝试在unwind.h
的垫片和libgccunwind.a
中加入Android.mk
,但仍会抛出相同的错误。我发现this thread黑客解决方案只是在垫片中声明原型,但是当我这样做时,我收到以下关于unwind.h
的错误
Error:(231, 3) error: previous declaration 'void _Unwind_SetGR(_Unwind_Context*, int, _Unwind_Word)' here
所以,当我声明它们时它能够找到它们的声明,因为它们会发生冲突,但是如果我不相信它们就不知道它们在哪里?我假设它必须与我的链接顺序有问题,但不确定如何解决它,因为在引入生锈的lib之后链接了所需的库。
非常感谢任何帮助!
修改1 在共享库创建期间调整要链接的makefile。
答案 0 :(得分:1)
对于静态库,LOCAL_LDLIBS没有意义(静态库没有链接)。每当您在真正的二进制文件(如共享库或可执行文件)中使用该库时,您都需要添加这些库。
答案 1 :(得分:-1)
解决方案恰好是构建展开并包含一些可移植性标头。请参阅模块示例here