Openssl compiling but ssl not working
Description
I am trying to compile cpr and openssl for android. It compiles without errors, but when I run it, if I send a request to a site with ssl, it does not give output, if I send a request without ssl, it gives output. Can you help me? How should CmakeLists.txt look like? How can I compile to Android arm64?
cmake -S . -B build -DANDROID_PLATFORM=android-30 -DCPR_ENABLE_SSL=ON
cmake_minimum_required(VERSION 3.25)
set(CMAKE_SYSTEM_NAME Android)
set(ANDROID_PLATFORM 30)
set(ANDROID_ABI arm64-v8a)
set(CMAKE_ANDROID_NDK "/home/ubuntu/android-ndk-r25b")
set(CMAKE_ANDROID_STL_TYPE c++_static)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_ANDROID_NDK}/build/cmake/android.toolchain.cmake")
set(TOOLCHAIN "${CMAKE_ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/")
set(CC ${TOOLCHAIN}/bin/aarch64-linux-android33-clang)
set(CXX ${TOOLCHAIN}/bin/aarch64-linux-android33-clang++)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN}/bin/aarch64-linux-android33-clang++)
set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/aarch64-linux-android33-clang)
set(CMAKE_CXX_STANDARD 20)
project(libcpr_with_openssl)
include(FetchContent)
FetchContent_Declare(
openssl
GIT_REPOSITORY https://github.com/openssl/openssl.git
GIT_TAG OpenSSL_1_1_1g
)
FetchContent_MakeAvailable(openssl)
find_package(OpenSSL REQUIRED)
set(CPR_FORCE_OPENSSL_BACKEND ON)
include(FetchContent)
FetchContent_Declare(cpr
GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG beb9e98806bb84bcc130a2cebfbcbbc6ce62b335)
FetchContent_MakeAvailable(cpr)
add_executable(${CMAKE_PROJECT_NAME} main.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE cpr::cpr OpenSSL::SSL OpenSSL::Crypto)
Example/How to Reproduce
- Create a
cpr::Session - Set option ...
- Perform the request
- See error
Possible Fix
No response
Where did you get it from?
GitHub (branch e.g. master)
Additional Context/Your Environment
- OS: Ubuntu
- Version: 22.04
Could you please try this one: https://github.com/libcpr/cpr/issues/884#issuecomment-1454662787
Could you please try this one: #884 (comment)
Nothing changed but I solved it the other way around . Please help me to solve it. A document explaining how to compile with mbedtls would be appreciated. I also managed to compile with openssl but I get this error when compiling with ndk on versions above this commit 7a02d67679308a19220e3b75616c18ff9e8deb5f9a.
[100%] Building CXX object CMakeFiles/libcpr_with_openssl.dir/main2.cpp.o [100%] Linking CXX executable libcpr_with_openssl ld: error: unable to find library -lstdc++fs clang++: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [CMakeFiles/libcpr_with_openssl.dir/build.make:101: libcpr_with_openssl] Error 1 make[1]: *** [CMakeFiles/Makefile2:168: CMakeFiles/libcpr_with_openssl.dir/all] Error 2 make: *** [Makefile:136: all] Error 2
There is such a library in ndk, but if we select c++20 standards without giving this parameter, it automatically links itself. I don't know how to fix it since I've never linked it manually with ndk, but putting it in the comment line worked for me :D
https://github.com/libcpr/cpr/blob/0490c5ad6848053f7e32675b309bb1313017cf8b/include/CMakeLists.txt#L63 this line
this is the only way I can compile the latest version. But I don't know the side effects. Also again, if you can help me how to compile it with mbedtls, I would really appreciate it. Just send me a small cmakelists.txt example ^^
@COM8
On Linux to use MBedTLS, you just have to set CPR_FORCE_MBEDTLS_BACKEND to ON.
So for example: cmake .. -DCPR_FORCE_MBEDTLS_BACKEND=ON, or set(CPR_FORCE_MBEDTLS_BACKEND ON) inside your CMake file.
I have never been a Android dev. If you provide me with a minimal project I can take a look at it.