Vcpkg: curl links with debug library even on Release configurations

Created on 2 Oct 2017  路  6Comments  路  Source: microsoft/vcpkg

Machine: Windows 10 x64 1703
Locale: en-US
Visual Studio 2017 Professional
Example Code: https://gist.github.com/henriquegemignani/ca8266a5c6def4ec4fc03e689646bfb8

Installed packages:
vcpkg install curl:x64-windows zlib:x64-windows

Instructions:

mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" -T host=x64 -DCMAKE_TOOLCHAIN_FILE=..\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET:STRING=x64-windows ..
cmake --build . --target curltest --config RelWithDebInfo
RelWithDebInfo\curltest.exe

Expcted:
Generated binary to run succesfully.

Actual:
libcurl-d.dll not found.

port-bug

All 6 comments

Waiting for this bug to be fixed, this is a possible workaround:

  find_package(CURL REQUIRED)
  if (WIN32)
    list(LENGTH CURL_LIBRARY CURL_LIBRARY_LENGTH)
    if (CURL_LIBRARY_LENGTH EQUAL 1)
      set(CURL_LIBRARY_DEBUG_LIB   ${CURL_LIBRARY})
       set(CURL_LIBRARY_RELEASE_LIB ${CURL_LIBRARY_DEBUG_LIB}/../../../lib/libcurl.lib)
        get_filename_component(CURL_LIBRARY_RELEASE_LIB ${CURL_LIBRARY_RELEASE_LIB} REALPATH)
        unset(CURL_LIBRARY CACHE)
        unset(CURL_LIBRARY)
        unset(CURL_LIBRARIES  CACHE)
        unset(CURL_LIBRARIES)
        set(CURL_LIBRARY "debug;${CURL_LIBRARY_DEBUG_LIB};optimized;${CURL_LIBRARY_RELEASE_LIB}")
        set(CURL_LIBRARIES ${CURL_LIBRARY})
    endif()
  endif()

Yeah, I hit the same problem. This appear to be caused by the name of the import library is the same between release and debug (just libcurl.lib, which will be installed into both vcpkg\installed\x64-windows\lib and vcpkg\installed\x64-windows\debug\lib, for instance).
In fact, the Curl portfile.cmake renames libcurl-d.lib to just libcurl.lib (also removes the _imp suffix).
Both paths are added to the CMAKE_PREFIX_PATH (in vcpkg\scripts\buildsystems\vcpkg.cmake), with the debug path taking precedence (this wouldn't happen if the release and debug library versions held distinguished names).
I'm not sure I understand why it fails to find libcurl-d.dll, and copy it to the output directory. Sure, we have already made the mistake of linking with the wrong library, but this is yet another problem.
Not sure what the "ultimate" solution here might be, and I'm not sure that the workaround you provided above is sufficiently robust or general (is this happening to any other libraries now?).

Still reproductible for "CMAKE_GENERATOR=Visual Studio 15 2017 Win64", but not for "CMAKE_GENERATOR=Ninja" (open folder "Open in Visual Studio" from Explorer).

I've pointed out the issue in #3053 and its patch #3220 has been ignored over half of a year. FindCURL.cmake in CMake had already fixed in 3.13, but here it has never been corrected yet.

In fact, the Curl portfile.cmake renames libcurl-d.lib to just libcurl.lib (also removes the _imp suffix).

This is a root cause for an incorrect behavior.

Hi Everyone,
It seems that the curl library name of the debug version in the latest version(7.61.1-2) has been changed to libcurl-d.dll. Any other questions?

Please open a new issue if this is still a problem for you. Thanks.

Was this page helpful?
0 / 5 - 0 ratings