Search code examples
visual-studio-codecmakelibcurlvcpkg

Curl installed with VCPKG won't link properly with CMake


I'm facing difficulties in correctly linking LIBCURL with CMakeLists in VSCode for my C project. Despite successfully installing curl with vcpkg, it still doesn't work.

Could someone provide guidance on setting up the CMakeLists file in VSCode to link LIBCURL.

Any assistance, code snippets, or examples would be greatly appreciated. Thank you!

Here's how my CMakeLists looks so far:

Path of VCPKG: C:/vcpkg

set(CMAKE_PREFIX_PATH "C:/vcpkg/installed/x64-windows/share")
find_package(CURL CONFIG REQUIRED)
include_directories("C:\\vcpkg\\installed\\x64-windows\\include\\")
add_executable(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE CURL::libcurl)

Error:

CMake Error at C:/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package):Could not find a configuration file for package "CURL" that is compatible
with requested version "".

The following configuration files were considered but not accepted:

  C:/vcpkg/installed/x64-windows/share/curl/CURLConfig.cmake, version: 8.1.2-DEV (64bit)

Solution

  • As said in the comments: You are probably mixing x86 and x64. While your vcpkg has x64 libraries installed your cmake project is somehow set to x86. This might happen if you use e.g. VS 2019 or below generator or you explicitly requested x86.
    Secondly please read the vcpkg manual how to use vcpkg correctly. Manually setting CMAKE_PREFIX_PATH or adding a hardcoded vcpkg paths to include_directories is not the correct approach.