c++windowscmakevcpkgbuild-tools

VCPKG + CMAKE not finding compatible version with requested version ""


I am trying to use VCPKG and CMAKE on a cpp project and am using the CPR library. I have been struggling to figure out what could be the cause of this error, re ran the get-started guide and other tutorials / blogs that are using cpr with vcpkg and is running fine with almost the exact same cmake config. What am I doing wrong?

I have ran the follow commands

vcpkg install 
vcpkg integrate install 

The cmake config I am using

cmake_minimum_required(VERSION 3.0.0)
project(Testing VERSION 0.1.0)

include(CTest)
enable_testing()

add_executable(Testing main.cpp)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

find_package(cpr CONFIG REQUIRED)
target_link_libraries(cpr PRIVATE cpr::cpr)

Full error output

[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=C:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET:STRING=x64-windows -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -Se:/programming/2022/cpp/Testing/cpp-vcpkg-cmake-example -Be:/programming/2022/cpp/Testing/cpp-vcpkg-cmake-example/build -G "Visual Studio 17 2022" -T host=x86 -A win32
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
[cmake] CMake Error at C:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake:826 (_find_package):
[cmake]   Could not find a configuration file for package "cpr" that is compatible
[cmake]   with requested version "".
[cmake] 
[cmake]   The following configuration files were considered but not accepted:
[cmake] 
[cmake]     C:/tools/vcpkg/installed/x64-windows/share/cpr/cprConfig.cmake, version: 1.9.0 (64bit)
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:13 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "E:/programming/2022/cpp/Testing/cpp-vcpkg-cmake-example/build/CMakeFiles/CMakeOutput.log".

I have thought about adding adding specific version cpr to cmake but could not figure out how to do it, but that should not even be the underlying problem in this situation.


Solution

  • -DVCPKG_TARGET_TRIPLET:STRING=x64-windows

    means x64-windows triplet/libraries will be used (->vcvars64)

    -G "Visual Studio 17 2022"

    means VS 2022 will be used (defaults to x64)

    -T host=x86

    means VS2022 x86 host tools will be used -> vcvars(32|x86_<?>)?

    -A win32

    means VS2022 will try to build for x86/win32 (overrides the default of x64). (-> vcvars32)

    As such VCPKG_TARGET_TRIPLET=x64-windows is incompatible with -A win32. Do either not pass the -A flag to cmake or don't set VCPKG_TARGET_TRIPLET and let the vcpkg toolchain automatically select it. CMake is telling you that the libraries it found (x64) cannot be used for the targeted architecture (x86)