leenjewel / openssl_for_ios_and_android

OpenSSL Library for iOS and Android
920 stars 317 forks source link

lib/libcrypto.a(c_zlib.o): undefined reference error #76

Open shinxxxxwon opened 5 months ago

shinxxxxwon commented 5 months ago

Thank you for your service.

I downloaded the built file from the link below and added it to the Android project. https://github.com/leenjewel/openssl_for_ios_and_android/releases/tag/20170105

Now set the corresponding openssl library in CMakeLists.txt.

cmake_minimum_required(VERSION 3.10)

set(ZLIB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/zlib/include")
set(ZLIB_LIBRARY_DIR "${CMAKE_SOURCE_DIR}/zlib/lib")

set(OPENSSL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/opensslLib/${ANDROID_ABI}/include")
set(OPENSSL_LIBRARY_DIR "${CMAKE_SOURCE_DIR}/opensslLib/${ANDROID_ABI}/lib")

include_directories(
                    ${OPENSSL_INCLUDE_DIR}
                    ${ZLIB_INCLUDE_DIR}
                    )

link_directories(${ZLIB_LIBRARY_DIR})

add_library(ssl STATIC IMPORTED)
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libssl.a)

add_library(crypto STATIC IMPORTED)
set_target_properties(crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libcrypto.a)

add_library(curl STATIC IMPORTED)
set_target_properties(curl PROPERTIES IMPORTED_LOCATION ${OPENSSL_LIBRARY_DIR}/libcurl.a)

# zlib 라이브러리 파일을 찾아서 설정
find_library(ZLIB_LIBRARY z PATHS ${ZLIB_LIBRARY_DIR})

if(NOT ZLIB_LIBRARY)
    message(FATAL_ERROR "zlib library not found")
endif()

add_library( native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/native/file1.c
             src/main/native/file2.c
            ...
             )

target_link_libraries( native-lib
                       ${ZLIB_LIBRARY}
                       curl
                       ssl
                       crypto
                       android
                       log
                       EGL
                       GLESv1_CM
                      )

When compiling, an error occurs.

  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function zlib_stateful_expand_block: error: undefined reference to 'inflate'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function zlib_stateful_compress_block: error: undefined reference to 'deflate'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function zlib_stateful_finish: error: undefined reference to 'inflateEnd'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function zlib_stateful_finish: error: undefined reference to 'deflateEnd'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function zlib_stateful_init: error: undefined reference to 'inflateInit_'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function zlib_stateful_init: error: undefined reference to 'deflateInit_'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_free: error: undefined reference to 'inflateEnd'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_free: error: undefined reference to 'deflateEnd'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_ctrl: error: undefined reference to 'deflate'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_ctrl: error: undefined reference to 'zError'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_write: error: undefined reference to 'deflate'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_write: error: undefined reference to 'zError'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_write: error: undefined reference to 'deflateInit_'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_read: error: undefined reference to 'inflate'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_read: error: undefined reference to 'zError'
  ../../../../opensslLib/armeabi-v7a/lib/libcrypto.a(c_zlib.o):c_zlib.c:function bio_zlib_read: error: undefined reference to 'inflateInit_'

Is there any way to solve the problem??

jiek233 commented 5 months ago

这是来自QQ邮箱的自动回复邮件。   您发送的邮件我已收到,我会在看到后尽快回复您。