Closed Zhaoyilunnn closed 8 months ago
@Zhaoyilunnn thanks for reporting. To me this looks like you are linking not correctly. You are linking as INTERFACE
. Try linking PRIVATE
or PUBLIC
since it's not a header only library.
Here is an example: https://github.com/libcpr/example-cmake-fetch-content/blob/main/CMakeLists.txt
@Zhaoyilunnn thanks for reporting. To me this looks like you are linking not correctly. You are linking as
INTERFACE
. Try linkingPRIVATE
orPUBLIC
since it's not a header only library. Here is an example: https://github.com/libcpr/example-cmake-fetch-content/blob/main/CMakeLists.txt
Hi @COM8 thanks a lot for your quick response. However, I have tried using PRIVATE
but faced the same error.
Moreover, the error acutally happens when linking cpr against my CLIENT_TEST
executable, where I originally use PUBLIC
instead of INTERFACE
. And this link error only happens when I set CMAKE_BUILD_TYPE
to Debug
(it builds successfully when not setting debug mode). So I guess the INTERFACE
setting is not the root cause.
Finally I find the root cause is the same as this issue: https://github.com/libcpr/cpr/issues/358.
Some other dependency of my projects may set D_GLIBCXX_DEBUG
, which caused link error of cpr.
I manually remove this flag in my project by string(REPLACE "-D_GLIBCXX_DEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
and build successfully.
@COM8 could you help investigate the reason why we cannot enable D_GLIBCXX_DEBUG
when debugging cpr-dependent projects?
Thanks
I find that this only impacts building unit tests using googletest, building other executables without linking to googletest works fine: https://github.com/Zhaoyilunnn/quafu-cpp/tree/main/examples/01_simple. Maybe CPR is not compatible with googletest in debug mode
Description
Link error when setting -DCMAKE_BUILD_TYPE=Debug, I have followed the instructions to link lipcpr to my project, see: https://github.com/Zhaoyilunnn/quafu-cpp/blob/main/CMakeLists.txt
Example/How to Reproduce
This will produce the link error, however, compilation runs successfully through
cmake ..
without settingCMAKE_BUILD_TYPE
Possible Fix
No response
Where did you get it from?
GitHub (branch e.g. master)
Additional Context/Your Environment