libcpr/cpr

Set propper runtime library for use in msvc project

Closed this issue · 5 comments

Description

Tried to build as static library for use in msvc project and got runtime mismatch with my library and cpr.
cpr had /md while I needed /mt

Example/How to Reproduce

  1. Build with -DBUILD_SHARED_LIBS=OFF
  2. Try to use in msvc project with /mt flag

Possible Fix

Adding this resolved the issue
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$CONFIG:Debug:Debug>")

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

I am new to cmake but as I understand this must be accounted on your side

COM8 commented

@Chrys4lisfag thanks for reporting. I'm not a Windows dev working with msvc so my knowledge here is limited.
Here is a full example for using cpr in CMake even on Windows: https://github.com/libcpr/example-cmake-fetch-content

This can be taken as starting point.

@Chrys4lisfag thanks for reporting. I'm not a Windows dev working with msvc so my knowledge here is limited. Here is a full example for using cpr in CMake even on Windows: https://github.com/libcpr/example-cmake-fetch-content

This can be taken as starting point.

Yeah, I've got no issues with cmake project. The only issue when I've build cpr as static library and tried to link it to my msvc project. It had crt linking type mismatch between cpr.lib and my msvc project, so I had to modify cpr library CmakeLists by adding "set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$CONFIG:Debug:Debug>")" this line to make it work.

@Chrys4lisfag How did you add this I am facing the same issue. I am using cmake fetch content to include cpr in my project. Where did you include set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$CONFIG:Debug:Debug>

@Chrys4lisfag How did you add this I am facing the same issue. I am using cmake fetch content to include cpr in my project. Where did you include set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$CONFIG:Debug:Debug>

I've added this directly in the cpr`s CMakeLists then built cpr library as static (-DBUILD_SHARED_LIBS=OFF) and used output .lib and includes in my project

COM8 commented

Closing this one as there seams no action required from the cpr side here.