通过NDK在Android项目中包含Crypto++库

3
我正在尝试将Crypto++(http://www.cryptopp.com/)包含在Android NDK项目中。我想要能够从我的C++代码中调用Crypto++成员函数。我认为我只需要在我的C++代码中包含Crypto++的头文件和源代码,但似乎无法使其正常工作。
我的C++文件如下所示:
#include <jni.h>
#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
using namespace CryptoPP;
...

将所有Crypto++的头文件和源文件放在cryptopp子目录中。

最初,我遇到了许多编译错误,因为无法找到标准的C++库,但我通过添加以下行的Application.mk来解决了这个问题:

APP_STL := stlport_static

使用ndk-build进行编译(标准版和crystax版本都试过),我遇到了以下错误:
ABI='armeabi'
ABI='armeabi-v7a'
ABI='x86'
Gdbserver      : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup       : libs/armeabi/gdb.setup
Compile++ thumb  : ndk-tests-cpp <= ndk-tests.cpp
In file included from jni/cryptopp/modes.h:7,
             from jni/ndk-tests.cpp:2:
jni/cryptopp/cryptlib.h: In static member function 'static void CryptoPP::NameValuePairs::ThrowIfTypeMismatch(const char*, const std::type_info&, const std::type_info&)':
jni/cryptopp/cryptlib.h:291: error: exception handling disabled, use -fexceptions to enable
make: *** [obj/local/armeabi/objs-debug/ndk-tests-cpp/ndk-tests.o] Error 1

我以前从未在NDK项目中包含过外部库 - 可能我只是忽略了一些基础知识。


在Crypto++维基上还可以查看Crypto++和Android - jww
1个回答

6

您需要为您的Android项目启用异常。请尝试将以下行包含在您的Applications.mk中:

APP_CPPFLAGS += -frtti 
APP_CPPFLAGS += -fexceptions

4
你说得对 - 我通过在Application.mk中使用APP_STL := gnustl_static和APP_CPPFLAGS += -fexceptions来使其正常运行。 - Hybrid System

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接