2014-09-24 191 views
3

我試圖使用Android-OpenSSLibraries進行AES解密的簡單測試程序。編譯器/鏈接器向我顯示一個錯誤。編譯:Android NDK編譯器openssl發生錯誤

error: undefined reference to 'AES_set_encrypt_key' 
error: undefined reference to 'AES_encrypt' 
error: undefined reference to 'AES_set_decrypt_key' 

這是我的Android.mk文件,

LOCAL_PATH := $(call my-dir) 
$(info $(LOCAL_PATH)) 
include $(CLEAR_VARS) 

LOCAL_MODULE := demo 
LOCAL_CFLAGS := -I/some/include/path 
LOCAL_LDLIBS := \ 
     -llog \ 
     -lz \ 
     -lm \ 

LOCAL_SRC_FILES := \ 
     aes_api.c \ 
     io_module.cpp \ 
     jni_native.cpp \ 
     JniConstants.cpp \ 
     JNIHelp.cpp \ 
     libcrypto.so \ 
    PosixFile.cpp \ 

LOCAL_C_INCLUDES := \ 
    $(LOCAL_PATH)/include \ 
    $(LOCAL_PATH)/include/openssl 
$(info $(LOCAL_C_INCLUDES)) 

LOCAL_SHARED_LIBRARIES := \ 
     $(LOCAL_PATH)/libcrypto.so 

include $(BUILD_SHARED_LIBRARY) 

回答

1

LOCAL_SHARED_LIBRARIES內容是不正確。您必須爲其指定模塊,而不是指向共享對象的路徑。

你應該定義這個變量之前執行以下操作:

include $(CLEAR_VARS) 

#Name it as you want, it doesn't matter. For consistency, let's name it LibCrypto 
LOCAL_MODULE := LibCrypto 
LOCAL_EXPORT_C_INCLUDES := <path/to/Libcrypto/includes> 
LOCAL_SRC_FILES := <path/to/libCrypto/shared/object>/libcrypto.so 

include $(PREBUILT_SHARED_LIBRARY) 

,然後在LOCAL_SHARED_LIBRARIES你直接用模塊的名字引用它:

LOCAL_SHARED_LIBRARIES := LibCrypto 

請注意,您可以添加更多的那一個通過定義其他這樣的「模塊」,您甚至可以預先建立自己(使用include $(BUILD_SHARED_LIBRARY)),然後通過以下方式引用多個模塊:

LOCAL_SHARED_LIBRARIES := module1 \ 
          module2 \ 
          ... 

我強烈建議您訪問,並保持約the Android.mk specification

+0

是的,你是right.But我照你說的,編譯器顯示我的另一個錯誤此鏈接:LOCAL_SRC_FILES應指向一個文件結尾「.a」以下文件不受支持:/libcrypto.so – user4073982 2014-09-24 09:47:58

+0

@ user4073982這很奇怪,我使用它,而且'PREBUILT_SHARED_LIBRARY'的文檔明確地說:「與'BUILD_SHARED_LIBRARY'和'BUILD_STATIC_LIBRARY'不同,'LOCAL_SRC_FILES '必須是預建的共享庫的單一路徑(例如, 'foo/libfoo.so'),而不是源文件。「 – JBL 2014-09-24 09:52:12

+0

是的,LOCAL_SRC_FILES是共享庫的路徑,在mk文件中是LOCAL_SRC_FILES:= $(LOCA_PATH)/libcrypto.so,但我不知道在哪裏 – user4073982 2014-09-24 09:59:56