我正在尝试使用 JNI 构建一个版本的Botan(用于加密算法的库)以在 Android 上运行一些本机 C++ 程序。
我已经使用 NDK 工具链(NDK R5b)成功地创建了一个 libbotan.so,没有任何错误。但是当我从我的 Android 项目(示例)编译我的源文件(exampleError.cpp)时,我收到以下错误:
Android NDK: WARNING: Unsupported source file extensions in /home/fensta/workspace
/Example/jni/Android.mk for module botan
Android NDK: sources
Android NDK: WARNING: Unsupported source file extensions in /home/fensta/workspace
/Example/jni/Android.mk for module botan
Android NDK: sources
Install : libbotan.so => libs/armeabi/libbotan.so
Compile++ thumb : fooBar <= exampleError.cpp
SharedLibrary : libfooBar.so
/home/fensta/workspace/Example/obj/local/armeabi/objs/fooBar/exampleError.o: In
function `LibraryInitializer':
/home/fensta/workspace/Example/jni/botan/botan_all.h:5593: undefined reference to `
Botan::LibraryInitializer::initialize(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&)'
/home/fensta/workspace/Example/obj/local/armeabi/objs/fooBar/exampleError.o: In
function `~LibraryInitializer':
/home/fensta/workspace/Example/jni/botan/botan_all.h:5595: undefined reference to `
Botan::LibraryInitializer::deinitialize()'
/home/fensta/workspace/Example/jni/botan/botan_all.h:5595: undefined reference to `
Botan::LibraryInitializer::deinitialize()'
/home/fensta/workspace/Example/obj/local/armeabi/objs/fooBar/exampleError.o: In
function `~LibraryInitializer':
/home/fensta/Programs/android-ndk-r5b/sources/cxx-stl/stlport/stlport
/stl/_string_base.h:156: undefined reference to `
Botan::LibraryInitializer::deinitialize()'
collect2: ld returned 1 exit status
make: *** [/home/fensta/workspace/Example/obj/local/armeabi/libfooBar.so] Error 1
这是我的 exampletError.cpp:
#include <jni.h>
#include <string>
#include <botan/botan_all.h>
using namespace Botan;
JNIEXPORT void JNICALL Java_test_example_example_simpleTestCall (JNIEnv *env, jobject
object){
LibraryInitializer init;// <- calling a random type from Botan fails
}
这里是对应的Java类createError.java: private native void simpleTestCall();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
...
simpleTestCall();
}
在这里你可以看到 Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libbotan
LOCAL_CPPFLAGS += -fexceptions
LOCAL_SRC_FILES := sources
LOCAL_C_INCLUDES := includes
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := fooBar
LOCAL_SRC_FILES := exampleError.cpp
LOCAL_SHARED_LIBRARIES:=
libbotan
LOCAL_CPPFLAGS += -fexceptions
include $(BUILD_SHARED_LIBRARY)
最后,但并非最不重要的 Application.mk:
APP_ABI := armeabi armeabi-v7a
APP_PROJECT_PATH := /home/fensta/workspace/Example
APP_STL := stlport_shared
注:JNI文件夹结构如下:Android.mk Application.mk botan/botan_all.h sources/botan_all.cpp exampleError.cpp
我还检查了 libbotan.so 的内容,如下所示:
/workspace/Example/obj/local/armeabi$ nm libbotan.so
00001234 a _DYNAMIC
000012bc a _GLOBAL_OFFSET_TABLE_
000012c8 A __bss_end__
000012c8 A __bss_start
000012c8 A __bss_start__
000012c8 D __data_start
000012c8 A __end__
00000233 A __exidx_end
00000233 A __exidx_start
000012c8 A _bss_end__
000012c8 A _edata
000012c8 A _end
但我不知道在这个输出中是否可以看到任何错误。此外,我还在网上搜索了这个错误,例如here。不幸的是,我还不能解决我的问题。
所以我的问题是:我做错了什么?