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

ndk stdc++fs library error #887

Merged
merged 2 commits into from
Aug 3, 2023
Merged

ndk stdc++fs library error #887

merged 2 commits into from
Aug 3, 2023

Conversation

turkic-dev
Copy link
Contributor

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)

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

@COM8 COM8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@COM8 COM8 requested a review from KingKili March 17, 2023 18:14
@COM8 COM8 modified the milestones: CPR 1.9.x, CPR 1.10.x Mar 17, 2023
@COM8 COM8 merged commit eb2d418 into libcpr:master Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants