janbar / openssl-cmake

Build OpenSSL with CMake on MacOS, Win32, Win64 and cross compile for Android, IOS
Other
277 stars 144 forks source link

Error while compiling code in android #7

Open sadeghhosseini opened 5 years ago

sadeghhosseini commented 5 years ago

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.

janbar commented 5 years ago

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})
peerless2012 commented 2 years ago

I build success for android with the latest version.