libcpr / cpr

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

CURLcode curl_mime_filename converting argument 2 from value type to const char* not possible #1051

Closed chill0r closed 1 month ago

chill0r commented 1 month ago

Description

When trying to compile cpr on windows with the msvc compiler the build fails with the following errors:

C2664 "CURLcode curl_mime_filename(curl_mimepart *, const char*)": Converting argument 2 from "const std::filesystem::path::value_type *" to "const char*" not possible

Example/How to Reproduce

  1. Create an new CMakeLists.txt with the following content:
    cmake_minimum_required (VERSION 3.8)
    set(CMAKE_CXX_STANDARD 17)
    project(test)
    add_library(test SHARED)
    target_sources(test PUBLIC test.h PRIVATE test.cpp)
    include(FetchContent)
    FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git)
    FetchContent_MakeAvailable(cpr)
    target_link_libraries(test PRIVATE cpr::cpr)
  2. Try to compile on windows with Visual Studio 2022 CE (MSVC 14.39.33519)

Possible Fix

The line in question is in session.cpp 958:

curl_mime_filename(mimePart, fs::path(file.filepath).filename().c_str());

after changing to

curl_mime_filename(mimePart, fs::path(file.filepath).filename().string().c_str());

it's working fine.

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

COM8 commented 1 month ago

@chill0r Thanks for reporting. Confirmed!