Statically link against Curl lib

I have the following code for fetching and linking against the Curl library:

include(FetchContent)
FetchContent_Declare(curl

	GIT_REPOSITORY "https://github.com/curl/curl.git"
	GIT_TAG "curl-8_6_0"
	GIT_SHALLOW TRUE)

FetchContent_MakeAvailable(curl)


target_link_libraries(${EXECUTABLE_NAME} PRIVATE CURL::libcurl)

The code functions correctly, but whenever I attempt to run my final executable build outside of my Integrated Development Environment (IDE), I encounter “DLL not found” errors. I’m interested in learning how I can instruct Curl to link statically so that I don’t have to deal with trying to find and copy DLL files.


PS: I did also tried the following command:

add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:exe> $<TARGET_FILE_DIR:exe>
COMMAND_EXPAND_LISTS)

This command works just fine for copying the DLL files, but I still get DLL not found errors. My guess is that Curl internally depends on some other things that are not being copied.

how I can instruct Curl to link statically

You mean how to build cURL as a static library? By default it seems to build as a dynamic/SHARED library, so you’ll need to set the configuration option to build a static variant too (or instead of) and then link to CURL::libcurl_static target instead of CURL::libcurl_shared.

1 Like