openssl-cmake icon indicating copy to clipboard operation
openssl-cmake copied to clipboard

Error while compiling code in android

Open sadeghhosseini opened this issue 6 years ago • 2 comments

I am trying to build and use this library in android. This is my cp/CMakeLists.txt's content:

cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        native-lib.cpp)

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)





file(GLOB_RECURSE OPENSSL_SOURCES "openssl/*.c")
include_directories(openssl/include)
add_library(openssl SHARED ${OPENSSL_SOURCES})



target_link_libraries( # Specifies the target library.
        native-lib
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

When I try to build this, I get this error: C:/Users/admin/AndroidStudioProjects/CPR/app/src/main/cpp/openssl/crypto/bn/bn_depr.c:15:10: fatal error: 'openssl/opensslconf.h' file not found

What is the problem? Thanks in advance.

sadeghhosseini avatar Oct 31 '19 12:10 sadeghhosseini

You have to use the cmake project provided with it by the following: I.e if you have copied this project into your source dir (CMAKE_CURRENT_SOURCE_DIR) with the path name "openssl":

# Provides dependency openssl
find_package(OpenSSL QUIET)
if(NOT OPENSSL_FOUND)
    add_subdirectory(
        ${CMAKE_CURRENT_SOURCE_DIR}/openssl
        ${CMAKE_CURRENT_BINARY_DIR}/openssl
        EXCLUDE_FROM_ALL
    )
    set(OPENSSL_SSL_LIBRARY ssl)
    set(OPENSSL_CRYPTO_LIBRARY crypto)
    set(OPENSSL_INCLUDE_DIR "${openssl_BINARY_DIR}/include" "${openssl_BINARY_DIR}")
    set(OPENSSL_FOUND ON)
    message(STATUS "Build OpenSSL: ${openssl_BINARY_DIR}")
endif()

set (HAVE_OPENSSL 1)
include_directories (${OPENSSL_INCLUDE_DIR})
...
target_link_libraries (native-lib  ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})

janbar avatar Oct 31 '19 14:10 janbar

I build success for android with the latest version.

peerless2012 avatar Jul 07 '22 08:07 peerless2012