Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NDK compiler openssl occur error [closed]

Tags:

c++

c

android

I tried to make simple test program with AES decryption using Android-OpenSSLibraries. The compiler/linker shows me an error. Compiler:

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

And this is my Android.mk file,

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)
like image 926
user4073982 Avatar asked Mar 29 '26 18:03

user4073982


1 Answers

Your LOCAL_SHARED_LIBRARIES content is incorrect. You must specify modules for it and not paths to shared objects.

You should have the following before defining this variable:

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)

and then in your LOCAL_SHARED_LIBRARIES you reference it directly with its module name:

LOCAL_SHARED_LIBRARIES := LibCrypto

Note that you can add more that one lib by defining other such "modules", that you can even build yourself beforehand (using include $(BUILD_SHARED_LIBRARY)) and then reference multiple module the following way:

LOCAL_SHARED_LIBRARIES := module1 \
                          module2 \
                          ...

I strongly encourage you to visit and keep this link about the Android.mk specification

like image 88
JBL Avatar answered Apr 01 '26 07:04

JBL