简体   繁体   English

CMake CMakeLists.txt:323 错误(消息):cl.exe(32 位)和 Visual Studio 生成器(64 位)不匹配

[英]CMake Error at CMakeLists.txt:323 (message): cl.exe (32-bit) and Visual Studio Generator (64-bit) do not match

It is my first time using cmake.这是我第一次使用 cmake。

So I am writing in the developer command prompt for vs 2022所以我在 vs 2022 的开发人员命令提示符中编写

C:\Users\KBSI\OpenMS\JK_contrib>cmake -DBUILD_TYPE=ALL -DNUMBER_OF_JOBS=4 -G "Visual Studio 17 2022" -A x64 "C:\Users\KBSI\OpenMS\contrib"

The result is below结果如下

CMake Error at CMakeLists.txt:323 (message):
  cl.exe (32-bit) and Visual Studio Generator (64-bit) do not match.  Please
  fix your PATH environment to find the proper cl.exe or use an appropriate
  generator by adding -A Win32/x64 to your CMake call.


-- Configuring incomplete, errors occurred!
See also "C:/Users/KBSI/OpenMS/JK_contrib/CMakeFiles/CMakeOutput.log".

So I am adding.....X64/cl.exe to path environment also.所以我也将 .....X64/cl.exe 添加到路径环境中。

but it didn't work.但它没有用。

please help me.请帮我。


The project you're trying to build puts some restrictions on the environment you run the cmake configuration from along with mentioning the reason for this:您尝试构建的项目对运行 cmake 配置的环境施加了一些限制,并说明了这样做的原因:

From OpenMS/contrib/CMakeLists.txt来自OpenMS/contrib/CMakeLists.txt

  ...
  ## check that the console environment has a cl.exe architecture which is identical to the VS Generator
  ## If cl.exe builds 32-bit libs and VS Generator is Win64, we'd end up with mixed 32bit/64bit libraries, depending on how each lib is build (Cmake, bjam, nmake)
  execute_process(COMMAND "cl.exe" OUTPUT_VARIABLE cl_out ERROR_VARIABLE cl_out)
  ##message(STATUS "Cl.exe said: ${cl_out}")
  if (cl_out MATCHES ".*x64.*")
    message(STATUS "Cl.exe produces: 64-bit")
    set(CL_ADDRESSMODEL 64)
  elseif (cl_out MATCHES ".*x86.*")
    message(STATUS "Cl.exe produces: 32-bit")
    set(CL_ADDRESSMODEL 32)
  else()
    message(FATAL_ERROR "Could not determine if cl.exe builds x86 or x64 apps. Make sure cl.exe is available in your environment!")
  endif()
  if (NOT (CL_ADDRESSMODEL EQUAL CONTRIB_ADDRESSMODEL))
    message(FATAL_ERROR "cl.exe (${CL_ADDRESSMODEL}-bit) and Visual Studio Generator (${CONTRIB_ADDRESSMODEL}-bit) do not match. Please fix your PATH environment to find the proper cl.exe or use an appropriate generator by adding -A Win32/x64 to your CMake call.")
  endif()
  ...

CONTRIB_ADDRESSMODEL is set depending on the compiler properties as detected CMake ( CMAKE_SIZEOF_VOID_P ). CONTRIB_ADDRESSMODEL的设置取决于检测到的编译器属性 CMake ( CMAKE_SIZEOF_VOID_P )。

Note that here cl.exe is executed from the current process to detect the architecture of the program used.请注意,这里的cl.exe是从当前进程执行的,以检测所使用程序的体系结构。 This program may be different to the compiler cmake chooses to use.该程序可能与 cmake 选择使用的编译器不同。

This requires you to make sure that both the compile chosen by cmake and cl.exe available in the command prompt both target x64 to set up the cmake project targeting x64.这要求您确保 cmake 选择的编译和命令提示符中可用的cl.exe都以 x64 为目标,以设置以 x64 为目标的 cmake 项目。 You'll need to run the correct ...\vcvarsall.bat x64 (or equivalent) before doing the cmake configuration.在执行 cmake 配置之前,您需要运行正确的...\vcvarsall.bat x64 (或等效程序)。

Alternatively you need edit the PATH environment variable manually to list the directory containing the cl.exe targeting x64 before any other directories containing cl.exe s that target different architectures.或者,您需要手动编辑PATH环境变量,以在包含针对不同体系结构的cl.exe的任何其他目录之前列出包含针对 x64 的cl.exe的目录。


Note: I haven't taken a look closer look at why exactly this CMake logic was added, but it sounds like a terrible choice.注意:我没有仔细研究为什么要添加这个 CMake 逻辑,但这听起来是个糟糕的选择。 Sure there are scenarios where you want to prevent building with an unexpected compiler, but there are CMake generators hardcoding the absolute paths to programs like the compiler and working with those is hindered by putting such a restriction in place...当然,在某些情况下您希望防止使用意外的编译器进行构建,但是有 CMake 生成器对编译器等程序的绝对路径进行了硬编码,并且由于设置了这样的限制而阻碍了使用这些程序......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM