# Statically link against Curl lib

**URL:** <https://discourse.cmake.org/t/statically-link-against-curl-lib/10324>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [March 8, 2024, 7:39am UTC](https://discourse.cmake.org/t/statically-link-against-curl-lib/10324 "2024-03-08T07:39:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saviz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/saviz/32/6194_2.png) [@Saviz](https://discourse.cmake.org/u/Saviz)\
**Post date:** [March 8, 2024, 7:39am UTC](https://discourse.cmake.org/t/statically-link-against-curl-lib/10324/1 "2024-03-08T07:39:29Z")

</div>

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

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [March 10, 2024, 10:02am UTC](https://discourse.cmake.org/t/statically-link-against-curl-lib/10324/2 "2024-03-10T10:02:28Z")

</div>

> how I can instruct Curl to link statically

You mean how to build cURL as a static library? By default it [seems](https://github.com/curl/curl/blob/5ce164e0e9290c96eb7d502173426c0a135ec008/CMakeLists.txt#L87) to build as a dynamic/SHARED library, so you’ll need to set the [configuration option](https://github.com/curl/curl/blob/5ce164e0e9290c96eb7d502173426c0a135ec008/CMakeLists.txt#L88) to build a static variant too (_or instead of_) and then link to `CURL::libcurl_static` target instead of `CURL::libcurl_shared`.
