2013-09-22 49 views
0

我想使用openssl的RSA,所以我需要用ndk.I將Android與openssl集成。我在https://github.com/aluvalasuman/OpenSSL1.0.1cForAndroid處下載Android的openssl的源代碼。 ndk-build在源文件夾中生成libcrypto.solibssl.so,我將其複製到$(MY_PROJECT)/ JNI/LIB /,然後鏈接它們Android.mk那樣:如何將openssl集成到Android?

LOCAL_PATH := $(call my-dir) 

include $(CLEAR_VARS) 
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include 
LOCAL_LIBS := $(LOCAL_PATH)/lib 
LOCAL_STATIC_LIBRARIES := libcrypto libssl 
LOCAL_LDLIBS := -llog 
LOCAL_MODULE := jni 

LOCAL_SRC_FILES := jni.c 

include $(BUILD_SHARED_LIBRARY) 

而測試一樣,在OpenSSL:

#include <stdio.h> 
#include <string.h> 

#include <openssl/rsa.h> 

#define nr_bits 2048 

int test_openssl() 
{ 
    RSA *rsa = RSA_generate_key(nr_bits, 65537, NULL, NULL); 
    return 0; 
} 

當我編譯它,把它扔到了錯誤:

....jni/license/license.c:10: error: undefined reference to 'RSA_generate_key' 
collect2: ld returned 1 exit status 

有誰知道WH問題在哪?如果有人能幫忙,我將非常感激。

回答

0

這樣的undefined reference錯誤通常表明編譯器/鏈接程序未在其路徑中找到libcrypto.so。您可以嘗試幾件事:

  1. 將-lcrypto添加到LOCAL_LDLIBS。這告訴編譯器在可能的情況下使用libcrypto.so來解析未定義的符號

  2. 將$(MY_PROJECT)/ jni/lib /添加到LOCAL_LIBS中,以便編譯器知道從哪裏選擇-lcrypto。這假定$(MY_PROJECT)在make文件中定義。

0

我知道這是一個老問題,但如果有人遇到此問題,他或她可以通過使用解決的問題:

LOCAL_STATIC_LIBRARIES := crypto 

,而不是

LOCAL_STATIC_LIBRARIES := libcrypto libssl 
相關問題