2012-04-02 37 views
3

我想在Android NDK項目中包含Crypto ++(http://www.cryptopp.com/)。我希望能夠從我的代碼的C++部分調用Crypto ++成員函數。我以爲我可以在我的C++代碼中包含來自Crypto ++的頭文件和源代碼,但我似乎無法使其工作。在Android項目中通過NDK包含Crypto ++庫

我的C++文件看起來像這樣:

#include <jni.h> 
#include "cryptopp/modes.h" 
#include "cryptopp/aes.h" 
using namespace CryptoPP; 
... 

與所有的加密++頭文件和源文件在cryptopp子目錄。

最初我接收到許多編譯自的標準C++庫的錯誤沒有被發現,但我固定,通過與下面的行添加Application.mk:

APP_STL := stlport_static 

與NDK建造編譯(兩個標準和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項目包括外部庫 - 也許我只是忽視的東西基本。

+0

另請參見[加密++和Android(http://www.cryptopp.com/wiki/Android_%28Command_Line%29)的加密+維基。 – jww 2015-05-02 22:45:52

回答

6

您必須爲您的Android項目啓用例外。嘗試將這些線包括到您的Applications.mk:

APP_CPPFLAGS += -frtti 
APP_CPPFLAGS += -fexceptions 
+4

你是對的 - 我通過使用:APP_STL:= gnustl_static和APP_CPPFLAGS + = Application.mk中的-fexceptions來實現它的工作 – 2012-05-02 19:40:02

+0

爲什麼不接受答案? :) – 2012-05-16 08:25:13