# Libcurl linking on windows

**URL:** https://discourse.cmake.org/t/libcurl-linking-on-windows/9259
**Category:** Usage
**Created:** [October 23, 2023, 5:40pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259 "2023-10-23T17:40:59Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Torsten](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@Torsten](https://discourse.cmake.org/u/Torsten)
#### Post date: [October 23, 2023, 5:40pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/1 "2023-10-23T17:40:59Z")

</div>

Trying to use curl, link fails on windows. I have created a minimal project to debug the problem

I have conanfile.txt

```auto
[requires]
libcurl/8.2.1

[generators]
CMakeDeps
CMakeToolchain

```

CMakeLists.txt:

```cmake
cmake_minimum_required(VERSION 3.15)
project(linkCurl VERSION 1.0 LANGUAGES CXX)

find_package(CURL REQUIRED)
include_directories(${libcurl_CURL_libcurl_INCLUDE_DIRS_RELEASE})

add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES})

```

Build commands:

```auto
C:\Users\torsiver\Projects\link_curl>conan install . --output-folder=build --build=missing [Seems to run OK - conan downloads the package]

cd build

C:\Users\torsiver\Projects\link_curl\build>cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release [seems to run OK]

C:\Users\torsiver\Projects\link_curl\build>cmake --build . [causes ERROR: error LNK2019: unresolved external symbol __imp_curl_easy_strerror]

```

I tried running with -v which shows this link command:

Link:

```auto
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\Users\torsiver\Projects\link_curl\build\Debug\linkCurl.exe" /INCREMENTAL /ILK:"linkCurl.dir\Debug\linkCurl.ilk" /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/Users/torsiver/Projects/link_curl/build/Debug/linkCurl.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/torsiver/Projects/link_curl/build/Debug/linkCurl.lib" /MACHINE:X64 /machine:x64 linkCurl.dir\Debug\main.obj

```

Seems CMake is not trying to link libcurl?

The project builds OK on linux (wsl2 Ubuntu 22.04.3 with default tools installed from apt)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 23, 2023, 7:03pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/2 "2023-10-23T19:03:52Z")

</div>

Is `CURL_LIBRARIES` set at all? Does it work if you remove the include directory as well and instead link to `CURL::libcurl`?

---

<div class="post-metadata">

### Author: ![Torsten](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@Torsten](https://discourse.cmake.org/u/Torsten)
#### Post date: [October 24, 2023, 6:43am UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/3 "2023-10-24T06:43:10Z")

</div>

I tried dumping all variables with this.

```auto
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

```

It seems CURL\_LIBRARIES is not set. I tried to use CURL::libcurl as shown below (the variable libcurl\_LIBRARIES\_RELEASE has this value so maybe i should be using this to get windows and linux consistent):

```auto
target_link_libraries(${PROJECT_NAME} CURL::libcurl)

```

This makes no difference (edited because my first conclusion was wrong, caused by an experiment).

It seems Conan has correctly downloaded the curl lib (this file exists after running Conan install: c:\Users\torsiver.conan2\p\libcu75d014a1ff3cb\p\lib\libcurl.lib), but somehow CMake is not picking it up correctly under windows.

CMake uses the correct include path during compile, so find\_package must have found the correct curl from Conan

```auto
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\CL.exe /c
  /IC:\Users\torsiver\.conan2\p\libcu75d014a1ff3cb\p\include /Zi /nologo /W1 /WX- /diagnostics:column /MP20 /Od /Ob0 /D
   _MBCS /D WIN32 /D _WINDOWS /D "CMAKE_INTDIR=\"Debug\"" /Gm- /EHsc /RTC1 /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope
   /Zc:inline /GR /std:c++14 /Fo"linkCurl.dir\Debug\\" /Fd"linkCurl.dir\Debug\vc142.pdb" /external:W1 /Gd /TP /errorRep
  ort:queue C:\Users\torsiver\Projects\link_curl\src\main.cpp
  main.cpp

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 24, 2023, 11:17am UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/4 "2023-10-24T11:17:26Z")

</div>

> [@Torsten](#):
>
> This makes no difference

It is odd to me that `FindCURL` would define a target without a library path to give it.

---

<div class="post-metadata">

### Author: ![Torsten](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@Torsten](https://discourse.cmake.org/u/Torsten)
#### Post date: [October 24, 2023, 12:57pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/5 "2023-10-24T12:57:34Z")

</div>

I tried to upgrade to CMake v 3.28 rc2, to be able to use the CURL\_USE\_STATIC\_LIBS hint as documented here [https://cmake.org/cmake/help/latest/module/FindCURL.html](https://cmake.org/cmake/help/latest/module/FindCURL.html)

I have a bit doubt whether i used the hint correctly - i could not find an example in the documentation. I tried this:

```auto
find_package(CURL REQUIRED HINTS CURL_USE_STATIC_LIBS)

```

The reason i am not sure is that the find\_package documentation says that HINTS accepts a directory name as argument, but CURL\_USE\_STATIC\_LIBS does not look like a directory name.

Doing this made no difference. Do i need more changes (specify someting different than CURL::libcurl to target\_link\_libraries, maybe?)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 24, 2023, 1:10pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/6 "2023-10-24T13:10:34Z")

</div>

Can you perhaps message around `FindCURL`’s creation of the `CURL::libcurl` target and see what values it is getting for various properties?

---

<div class="post-metadata">

### Author: ![Torsten](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@Torsten](https://discourse.cmake.org/u/Torsten)
#### Post date: [October 24, 2023, 1:14pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/7 "2023-10-24T13:14:42Z")

</div>

I am not very experienced in CMake. What exactly do you want me to message? How do i output the contents of CURL::libcurl

Can you specify the syntax for the massage call?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 24, 2023, 1:15pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/8 "2023-10-24T13:15:51Z")

</div>

I would copy the `set_target_properties` call(s) and change `set_target_properties` to `message`. It’ll drop spaces, but it should be good enough to see if things are at least sane.

---

<div class="post-metadata">

### Author: ![Torsten](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@Torsten](https://discourse.cmake.org/u/Torsten)
#### Post date: [October 24, 2023, 1:29pm UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/9 "2023-10-24T13:29:52Z")

</div>

I did this in cmakedeps\_macros.cmake in the build dir (and other places that did not fire):

```auto
		      message("Before3: " ${_LIB_NAME} PROPERTIES IMPORTED_IMPLIB${config_suffix} ${CONAN_FOUND_LIBRARY})
              set_target_properties(${_LIB_NAME} PROPERTIES IMPORTED_LOCATION${config_suffix} ${CONAN_FOUND_LIBRARY} IMPORTED_NO_SONAME ${no_soname_mode})

```

Result:

```auto
C:\Users\torsiver\Projects\link_curl\build>cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
-- Using Conan toolchain: C:/Users/torsiver/Projects/link_curl/build/conan_toolchain.cmake
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- Conan: Component target declared 'CURL::libcurl'
Before3: CONAN_LIB::libcurl_libcurl_RELEASEPROPERTIESIMPORTED_IMPLIB_RELEASEC:/Users/torsiver/.conan2/p/libcu75d014a1ff3cb/p/lib/libcurl.lib
Before3: CONAN_LIB::libcurl_CURL_libcurl_libcurl_RELEASEPROPERTIESIMPORTED_IMPLIB_RELEASEC:/Users/torsiver/.conan2/p/libcu75d014a1ff3cb/p/lib/libcurl.lib
-- Conan: Component target declared 'OpenSSL::Crypto'
-- Conan: Component target declared 'OpenSSL::SSL'
-- Conan: Target declared 'openssl::openssl'
Before3: CONAN_LIB::openssl_libssl_RELEASEPROPERTIESIMPORTED_IMPLIB_RELEASEC:/Users/torsiver/.conan2/p/opens00e605497815b/p/lib/libssl.lib
Before3: CONAN_LIB::openssl_libcrypto_RELEASEPROPERTIESIMPORTED_IMPLIB_RELEASEC:/Users/torsiver/.conan2/p/opens00e605497815b/p/lib/libcrypto.lib
Before3: CONAN_LIB::openssl_OpenSSL_SSL_libssl_RELEASEPROPERTIESIMPORTED_IMPLIB_RELEASEC:/Users/torsiver/.conan2/p/opens00e605497815b/p/lib/libssl.lib
Before3: CONAN_LIB::openssl_OpenSSL_Crypto_libcrypto_RELEASEPROPERTIESIMPORTED_IMPLIB_RELEASEC:/Users/torsiver/.conan2/p/opens00e605497815b/p/lib/libcrypto.lib
-- Conan: Target declared 'ZLIB::ZLIB'
Before3: CONAN_LIB::zlib_zlib_RELEASEPROPERTIESIMPORTED_IMPLIB_RELEASEC:/Users/torsiver/.conan2/p/zlib462c154a4e854/p/lib/zlib.lib
-- Conan: Including build module from 'C:/Users/torsiver/.conan2/p/opens00e605497815b/p/lib/cmake/conan-official-openssl-variables.cmake'
linkCurlCURL::libcurl
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/torsiver/Projects/link_curl/build

```

The logging is from the else block of “if(is\_host\_windows AND library\_type STREQUAL “SHARED”)”

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 29, 2023, 11:46am UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/10 "2023-10-29T11:46:33Z")

</div>

This feels like something Conan is not setting up properly rather than CMake’s `FindCURL`. I’d ask the Conan folks about it, but if something is wrong on CMake’s side, feel free to report back here.

---

<div class="post-metadata">

### Author: ![Torsten](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/8e8cbc/32.png) [@Torsten](https://discourse.cmake.org/u/Torsten)
#### Post date: [October 31, 2023, 9:13am UTC](https://discourse.cmake.org/t/libcurl-linking-on-windows/9259/11 "2023-10-31T09:13:52Z")

</div>

I will try. Thanks for the assistance. Maybe in time i will be able to dig deeper on my own, but i am still a rookie in Conan/CMake
