gpt4 book ai didi

c++ - 如何修复 'Vcpkg/CMake Is Unable to determine target architecture'(Windows10、vcpkg、clion、cmake)

转载 作者:行者123 更新时间:2023-12-01 19:26:15 25 4
gpt4 key购买 nike

我想使用这个库,请参阅:https://github.com/jtv/libpqxx

我决定安装这个库管理器vcpkg,请参阅:https://github.com/microsoft/vcpkg

我将 CMake 选项设置为“CMake 项目应使用:”-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake”

这是错误:

"C:\Program Files\JetBrains\CLion 2019.1.4\bin\cmake\win\bin\cmake.exe"     -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/vcpkg/scripts   /buildsystems/vcpkg.cmake -G "CodeBlocks - MinGW Makefiles" C:\Users  \Vaio\CLionProjects\untitled
CMake Warning at C:/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake:68 (message):
Unable to determine target architecture, continuing without vcpkg.
Call Stack (most recent call first):
cmake-build-debug-mingw/CMakeFiles/3.14.3/CMakeSystem.cmake:6 (include)
CMakeLists.txt:2 (project)

对应的CMake代码是这样的:

if(VCPKG_TARGET_TRIPLET)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$")
set(_VCPKG_TARGET_TRIPLET_ARCH x86)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Xx]64$")
set(_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Aa][Rr][Mm]64$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm64)
else()
if(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015 Win64$")
set(_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015 ARM$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 14 2015$")
set(_VCPKG_TARGET_TRIPLET_ARCH x86)
elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 15 2017 Win64$")
set(_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 15 2017 ARM$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 15 2017$")
set(_VCPKG_TARGET_TRIPLET_ARCH x86)
elseif(CMAKE_GENERATOR MATCHES "^Visual Studio 16 2019$")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Xx]86$")
set(_VCPKG_TARGET_TRIPLET_ARCH x86)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Aa][Mm][Dd]64$")
set(_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Aa][Rr][Mm]$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^[Aa][Rr][Mm]64$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm64)
else()

endif()
else()
find_program(_VCPKG_CL cl)
if(_VCPKG_CL MATCHES "amd64/cl.exe$" OR _VCPKG_CL MATCHES "x64/cl.exe$")
set(_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(_VCPKG_CL MATCHES "arm/cl.exe$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(_VCPKG_CL MATCHES "arm64/cl.exe$")
set(_VCPKG_TARGET_TRIPLET_ARCH arm64)
elseif(_VCPKG_CL MATCHES "bin/cl.exe$" OR _VCPKG_CL MATCHES "x86/cl.exe$")
set(_VCPKG_TARGET_TRIPLET_ARCH x86)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(_VCPKG_TARGET_TRIPLET_ARCH x64)
else()
if( _CMAKE_IN_TRY_COMPILE )
message(STATUS "Unable to determine target architecture, continuing without vcpkg.")
else()
message(WARNING "Unable to determine target architecture, continuing without vcpkg.")
endif()
set(VCPKG_TOOLCHAIN ON)
return()
endif()
endif()
endif()

这是我所做的一步一步。

  1. 已安装 Visual Studio 2019
  2. 已安装 GIT
  3. 已安装 CMake
  4. 已安装 vcpkg,请参阅:https://github.com/microsoft/vcpkg安装命令:.\bootstrap-vcpkg.bat5 运行:vcpkg install libpqxx --triplet x64-windows
  5. 运行 : vcpkg list//查看它是否已安装
  6. 运行:vcpkg集成安装
  7. 在 CLion/CMake 内指定 -DCMAKE-TOOLCHAIN-FILE

我使用 MinGW/GNU 作为编译器

是不是我漏掉了什么?或者为什么它找不到我的目标架构?这是我的环境变量。

注意:Visual Studio 2019 中一切正常

enter image description here

最佳答案

我在 -DCMAKE_TOOLCHAIN_FILE 之前添加了 -DVCPKG_TARGET_TRIPLET=x64-windows 并且它起作用了。

解决方案链接: https://vcpkg.readthedocs.io/en/latest/users/integration/

使用 CMake,您可以在配置行上设置 VCPKG_TARGET_TRIPLET:

cmake ../my/project -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=...

如果您使用VCPKG_DEFAULT_TRIPLET环境变量来控制vcpkg命令行中的非限定三元组,您可以在CMake中默认VCPKG_TARGET_TRIPLET,例如

使用环境变量而不是命令行选项:

if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
endif()

关于c++ - 如何修复 'Vcpkg/CMake Is Unable to determine target architecture'(Windows10、vcpkg、clion、cmake),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57092692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com