我在IOS中成功编译并执行了Cryptopp,但我真的很难在android中工作。
这里我使用的是Cryptopp 5.6.3,NDK r10e和android studio 1.5,我可以通过ndk-build成功构建libcryptopp.so但它通过了一些错误,例如未定义引用'vtable for CryptoPP :: AutoSeededX917RNG'当我通过android studio进行重建。
在Android.mk
std::vector<T> v;
detect_corners(frame, std::back_inserter(v));
Application.mk中的
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := crypt_user
LOCAL_SRC_FILES := crypt_user.cpp
LOCAL_SHARED_LIBRARIES := cryptopp
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libcryptopp.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
build.gradle中的
APP_ABI := armeabi
APP_CPPFLAGS += -fexceptions -frtti
APP_STL := stlport_shared
#APP_STL := gnustl_shared
在crypt_user.cpp
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.kasbah.jeeva.ndklearning"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
moduleName = "crypt_user"
cFlags("-fexceptions")
stl = "stlport_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
jniDebuggable true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
当我没有使用任何与cryptopp相关的代码时,我可以成功编译它。
请帮助我解决这个问题,因为我正在与这个问题战斗超过2周..
答案 0 :(得分:1)
...未定义引用
等错误的数量'vtable for CryptoPP::AutoSeededX917RNG'
使用nm
确保符号存在:
$ arm-linux-androideabi-nm -D --demangle libcryptopp.so | grep AutoSeededX917RNG | sed 's|CryptoPP::||g'
00181ec4 W AutoSeededX917RNG<Rijndael>::IncorporateEntropy(unsigned char const*, unsigned int)
0017d728 W AutoSeededX917RNG<Rijndael>::GenerateIntoBufferedTransformation(BufferedTransformation&, std::string const&, unsigned long long)
00181c18 W AutoSeededX917RNG<Rijndael>::Reseed(unsigned char const*, unsigned int, unsigned char const*, unsigned char const*)
00181ddc W AutoSeededX917RNG<Rijndael>::Reseed(bool, unsigned char const*, unsigned int)
00181e80 W AutoSeededX917RNG<Rijndael>::AutoSeededX917RNG(bool, bool)
00181e80 W AutoSeededX917RNG<Rijndael>::AutoSeededX917RNG(bool, bool)
00169d90 W AutoSeededX917RNG<Rijndael>::~AutoSeededX917RNG()
00169d6c W AutoSeededX917RNG<Rijndael>::~AutoSeededX917RNG()
00169d6c W AutoSeededX917RNG<Rijndael>::~AutoSeededX917RNG()
0017d724 W AutoSeededX917RNG<Rijndael>::CanIncorporateEntropy() const
0023336c D typeinfo for AutoSeededX917RNG<Rijndael>
001fe0bc R typeinfo name for AutoSeededX917RNG<Rijndael>
00232308 V vtable for AutoSeededX917RNG<Rijndael>
在Application.mk中的
...
以下是我的Android.mk
对于提供随机数的共享对象的看法。你可以在Android-PRNG的GitHub上找到它。注意STLport的东西是第一个,Crypto ++的东西是第二个,然后PRNG库是第三个。
PRNG图书馆很简单。它包含一个文件 - libprng.cpp
。它对传感器进行采样,为随机数发生器开发种子。 Android Java调用PRNG库。
LOCAL_PATH := $(call my-dir)
# NDK_DEBUG_IMPORTS := 1
#########################################################
# STLport library
include $(CLEAR_VARS)
STLPORT_INCL := /opt/android-ndk-r10d/sources/cxx-stl/stlport/stlport
STLPORT_LIB := /opt/android-ndk-r10d/sources/cxx-stl/stlport/libs/$(TARGET_ARCH_ABI)
LOCAL_MODULE := stlport_shared
LOCAL_SRC_FILES := $(STLPORT_LIB)/libstlport_shared.so
LOCAL_EXPORT_CPPFLAGS :=
LOCAL_EXPORT_C_INCLUDES := $(STLPORT_INCL)
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_SHARED_LIBRARIES := stlport_shared
#########################################################
# Crypto++ library
include $(CLEAR_VARS)
CRYPTOPP_INCL := /usr/local/cryptopp/android-$(TARGET_ARCH_ABI)/include
CRYPTOPP_LIB := /usr/local/cryptopp/android-$(TARGET_ARCH_ABI)/lib
LOCAL_MODULE := cryptopp
LOCAL_SRC_FILES := $(CRYPTOPP_LIB)/libcryptopp.so
LOCAL_EXPORT_CPPFLAGS := -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function
LOCAL_EXPORT_C_INCLUDES := $(CRYPTOPP_INCL) $(CRYPTOPP_INCL)/cryptopp
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_SHARED_LIBRARIES := cryptopp
#########################################################
# PRNG library
include $(CLEAR_VARS)
APP_STL := stlport_shared
APP_MODULES := prng stlport_shared cryptopp
# My ass... LOCAL_EXPORT_C_INCLUDES is useless
LOCAL_C_INCLUDES := $(STLPORT_INCL) $(CRYPTOPP_INCL)
LOCAL_CPP_FEATURES := rtti exceptions
LOCAL_CPP_FLAGS := -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function
LOCAL_CPP_FLAGS += -Wl,--exclude-libs,ALL
LOCAL_LDLIBS := -llog -landroid
LOCAL_SHARED_LIBRARIES := cryptopp stlport_shared
LOCAL_MODULE := prng
LOCAL_SRC_FILES := libprng.cpp
include $(BUILD_SHARED_LIBRARY)
使用ndk-build
:
~$ cd Android-PRNG
Android-PRNG$ ndk-build
Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
[armeabi] Gdbserver : [arm-linux-androideabi-4.8] libs/armeabi/gdbserver
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
[x86] Gdbserver : [x86-4.8] libs/x86/gdbserver
[x86] Gdbsetup : libs/x86/gdb.setup
[mips] Gdbserver : [mipsel-linux-android-4.8] libs/mips/gdbserver
[mips] Gdbsetup : libs/mips/gdb.setup
[armeabi-v7a] Gdbserver : [arm-linux-androideabi-4.8] libs/armeabi-v7a/gdbserver
[armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup
[x86_64] Gdbserver : [x86_64-4.9] libs/x86_64/gdbserver
[x86_64] Gdbsetup : libs/x86_64/gdb.setup
[armeabi] Prebuilt : libcryptopp.so <= /usr/local/cryptopp/android-armeabi/lib/
[armeabi] Install : libcryptopp.so => libs/armeabi/libcryptopp.so
[armeabi] Compile++ thumb: prng <= libprng.cpp
[armeabi] Prebuilt : libstlport_shared.so <= /opt/android-ndk-r10d/sources/cxx-stl/stlport/libs/armeabi/
[armeabi] StaticLibrary : libstdc++.a
[armeabi] SharedLibrary : libprng.so
[armeabi] Install : libprng.so => libs/armeabi/libprng.so
[armeabi] Install : libstlport_shared.so => libs/armeabi/libstlport_shared.so
[x86] Prebuilt : libcryptopp.so <= /usr/local/cryptopp/android-x86/lib/
[x86] Install : libcryptopp.so => libs/x86/libcryptopp.so
[x86] Compile++ : prng <= libprng.cpp
[x86] Prebuilt : libstlport_shared.so <= /opt/android-ndk-r10d/sources/cxx-stl/stlport/libs/x86/
[x86] StaticLibrary : libstdc++.a
[x86] SharedLibrary : libprng.so
[x86] Install : libprng.so => libs/x86/libprng.so
[x86] Install : libstlport_shared.so => libs/x86/libstlport_shared.so
[mips] Prebuilt : libcryptopp.so <= /usr/local/cryptopp/android-mips/lib/
[mips] Install : libcryptopp.so => libs/mips/libcryptopp.so
[mips] Compile++ : prng <= libprng.cpp
[mips] Prebuilt : libstlport_shared.so <= /opt/android-ndk-r10d/sources/cxx-stl/stlport/libs/mips/
[mips] StaticLibrary : libstdc++.a
[mips] SharedLibrary : libprng.so
[mips] Install : libprng.so => libs/mips/libprng.so
[mips] Install : libstlport_shared.so => libs/mips/libstlport_shared.so
[armeabi-v7a] Prebuilt : libcryptopp.so <= /usr/local/cryptopp/android-armeabi-v7a/lib/
[armeabi-v7a] Install : libcryptopp.so => libs/armeabi-v7a/libcryptopp.so
[armeabi-v7a] Compile++ thumb: prng <= libprng.cpp
[armeabi-v7a] Prebuilt : libstlport_shared.so <= /opt/android-ndk-r10d/sources/cxx-stl/stlport/libs/armeabi-v7a/
[armeabi-v7a] StaticLibrary : libstdc++.a
[armeabi-v7a] SharedLibrary : libprng.so
[armeabi-v7a] Install : libprng.so => libs/armeabi-v7a/libprng.so
[armeabi-v7a] Install : libstlport_shared.so => libs/armeabi-v7a/libstlport_shared.so
[x86_64] Prebuilt : libcryptopp.so <= /usr/local/cryptopp/android-x86_64/lib/
[x86_64] Install : libcryptopp.so => libs/x86_64/libcryptopp.so
[x86_64] Compile++ : prng <= libprng.cpp
[x86_64] Prebuilt : libstlport_shared.so <= /opt/android-ndk-r10d/sources/cxx-stl/stlport/libs/x86_64/
[x86_64] StaticLibrary : libstdc++.a
[x86_64] SharedLibrary : libprng.so
[x86_64] Install : libprng.so => libs/x86_64/libprng.so
[x86_64] Install : libstlport_shared.so => libs/x86_64/libstlport_shared.so