c++ 错误代码:323(消息):cl.exe(32比特)和Visual Studio产生器(64比特)不相符

new9mtju  于 2022-12-01  发布在  其他
关注(0)|答案(1)|浏览(148)

这是我第一次使用cmake。
所以我在开发者命令提示符中写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"

结果如下

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".

因此,我也将X64/cl.exe添加到环境路径中。
但没有成功。
请帮帮我。

hmae6n7t

hmae6n7t1#

您尝试构建的项目对运行cmake配置的环境有一些限制,并说明了原因:
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的设置取决于检测到的CMake(CMAKE_SIZEOF_VOID_P)的编译器属性。
注意,这里cl.exe是从当前进程执行的,以检测所用程序的体系结构。该程序可能与编译器cmake选择使用的不同。
这要求您确保cmake选择的编译和命令提示符中可用的cl.exe都以x64为目标,以设置以x64为目标的cmake项目。在进行cmake配置之前,您需要运行正确的...\vcvarsall.bat x64(或等效程序)。
或者,您需要手动编辑PATH环境变量,以便在列出包含面向不同体系结构得cl.exe得任何其他目录之前列出包含面向x64得cl.exe得目录.
注意:我还没有仔细研究为什么要添加这个CMake逻辑,但听起来这是一个糟糕的选择。当然,有些情况下您希望避免使用意外的编译器进行编译,但有些CMake生成器硬编码到程序的绝对路径,如编译器,使用这些生成器会受到这样的限制的阻碍...

相关问题