Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shinxxxxwon opened this issue Mar 20, 2024 · 1 comment
Open

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

shinxxxxwon opened this issue Mar 20, 2024 · 1 comment

Comments

@shinxxxxwon
Copy link

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
Copy link

jiek233 commented Mar 20, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants