gpt4 book ai didi

Android - 未定义对 cryptopp 的引用

转载 作者:行者123 更新时间:2023-11-30 05:34:36 27 4
gpt4 key购买 nike

我在 IOS 中成功编译并执行了 Cryptopp,但我真的很难在 Android 中使用它。

在这里,我使用的是 Cryptopp 5.6.3、NDK r10e 和 android studio 1.5,我可以通过 ndk-build 成功构建 libcryptopp.so,但它会遇到一些错误,例如 undefined reference “vtable for CryptoPP::AutoSeededX917RNG”,当我通过 android studio 进行重建。

在Android.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)

在 Application.mk 中

APP_ABI := armeabi
APP_CPPFLAGS += -fexceptions -frtti
APP_STL := stlport_shared
#APP_STL := gnustl_shared

在 build.gradle 中

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'
}

在 crypt_user.cpp 中

#include <jni.h>
#include "../cryptopp/include/cryptlib.h"

#include "../cryptopp/include/osrng.h"
//using CryptoPP::AutoSeededRandomPool;
using CryptoPP::AutoSeededX917RNG;

#include "../cryptopp/include/aes.h"
using CryptoPP::AES;

#ifdef __cplusplus
extern "C" {
#endif
jlong Java_com_kasbah_jeeva_ndklearning_MainActivity_fun
(JNIEnv* env, jobject o, jint i) {

AutoSeededX917RNG<AES> rng;

long long t = CryptoPP::INFINITE_TIME / i;
return t;
}
#ifdef __cplusplus
}
#endif

当我没有使用任何cryptopp相关代码时,我可以成功编译它。

请帮我解决这个问题,因为我已经为此奋斗了 2 个多星期..

enter image description here

enter image description here

最佳答案

... number of errors like undefined reference to '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>

in Application.mk
...

下面是我的 Android.mk 看起来像一个提供随机数的共享对象。您可以在 GitHub 上找到它 Android-PRNG .请注意,首先是 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)

GitHub 项目使用 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

关于Android - 未定义对 cryptopp 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34156787/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com