-
Notifications
You must be signed in to change notification settings - Fork 942
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
Unable to statically link with CPM #1137
Comments
@Sightem thanks for reporting! When I try building both cmake_minimum_required(VERSION 3.20)
project(cpr_example)
set(CMAKE_CXX_STANDARD 17)
# Set to C++ 11 if you are using cpr <= 1.9.x
# More: https://github.com/libcpr/cpr#supported-releases
# set(CMAKE_CXX_STANDARD 11)
# Set a default build type if none was specified
# Based on: https://github.com/openchemistry/tomviz/blob/master/cmake/BuildType.cmake
set(DEFAULT_BUILD_TYPE "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(DEFAULT_BUILD_TYPE "Debug")
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
add_executable(cpr_example main.cpp)
if(WIN32) # Install dlls in the same directory as the executable on Windows
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
endif()
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
set(CPR_FORCE_USE_SYSTEM_CURL OFF CACHE INTERNAL "" FORCE)
set(CPR_BUILD_TESTS OFF CACHE INTERNAL "" FORCE)
set(CPR_ENABLE_SSL OFF CACHE INTERNAL "" FORCE)
set(CURL_ZLIB OFF CACHE INTERNAL "" FORCE)
target_link_options(cpr_example PUBLIC -static -static-libgcc -static-libstdc++)
include(FetchContent)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/libcpr/cpr.git
GIT_TAG 1.11.0)
FetchContent_MakeAvailable(cpr)
target_link_libraries(cpr_example PRIVATE cpr::cpr) I run into a different problem:
If I remove the
I suspect curl linkage is not purely static and relies on some shared dependencies that can be build and then used. |
Oddly enough, from my own example I get these results. This is with the
Below is the output without the
Even weirder, your example works perfectly somehow with no linking errors, Though ldd still yields some strange results:
Going back to the example you provided, it appears that setting I cannot seem to reproduce the exact problem you are having however |
Description
It appears that the library has trouble with static linking (specifically in debug mode) when included using CPM.
I cannot reproduce this when building in release or release with debug info modes.
This problem appears to have been caused by a change in v1.11.0, as I cannot reproduce this using v1.9.8
Example/How to Reproduce
Possible Fix
No response
Where did you get it from?
Other (specify in "Additional Context/Your Environment")
Additional Context/Your Environment
The text was updated successfully, but these errors were encountered: