libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.59k stars 937 forks source link

ndk stdc++fs library error #887

Closed turkic-dev closed 1 year ago

turkic-dev commented 1 year ago

I only get this error when compiling with ndk. Linux has no problem, it compiles on Linux with or without the -lstdc++fs flag, but ndk cannot find such a library, but you can use the filesystem library without this flag (-lstdc+++fs).

This change is necessary to improve compatibility and usability of the cpr library. Thank you for your attention to this issue.

//main.cpp
#include <cpr/cpr.h>
#include <iostream>
int main()
{
    cpr::Response r = cpr::Get(cpr::VerifySsl(false),cpr::Url{"http://api.github.com/repos/whoshuu/cpr/contributors"});
    std::cout << r.status_code << std::endl;
    std::cout << r.text << std::endl;
    return 0;
}
cmake_minimum_required(VERSION 3.25)
set(CMAKE_SYSTEM_NAME Android)
set(ANDROID_PLATFORM 33)
set(ANDROID_ABI arm64-v8a)
set(CMAKE_ANDROID_NDK "/home/android-ndk-r25c-linux/android-ndk-r25c")
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(CMAKE_CXX_COMPILER ${TOOLCHAIN}/bin/aarch64-linux-android33-clang++)
set(CMAKE_C_COMPILER ${TOOLCHAIN}/bin/aarch64-linux-android33-clang)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CPR_ENABLE_SSL oFF)
set(BUILD_SHARED_LIBS OFF)

project(libcpr_test)

include(FetchContent)
FetchContent_Declare(cpr 
    GIT_REPOSITORY https://github.com/libcpr/cpr.git 
    GIT_TAG master)
FetchContent_MakeAvailable(cpr)

add_executable(${CMAKE_PROJECT_NAME} main.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC cpr::cpr)

if it is compiled using ndk it gives this error. ld: error: unable to find library -lstdc++fs clang++: error: linker command failed with exit code 1 (use -v to see invocation)