CMake 为什么坚持要求使用的处理器是 x86_64,而实际上是 arm64?

huangapple go评论83阅读模式
英文:

Why does CMake insist that the processor used is x86_64 when it is actually arm64?

问题

我正在使用CMake 3.25.1在M1 Mac(Monterey 12.4)上,并尝试检测苹果设备上使用的架构(以便根据需要利用M1加速有条件地编译我的程序)。问题是,使用这个CMakeLists.txt文件时,CMake会告诉我它正在使用x86_64。发生了什么?

英文:

I am using CMake 3.25.1 on an M1 Mac (Monterey 12.4) and am trying to detect the architecture used on an apple machine (so that I can conditionally compile my program to take advantage of M1 acceleration if I can). The problem is that, with this CMakeLists.txt:

cmake_minimum_required(VERSION 3.25.1)
project(test)

if(APPLE)
    message("Apple detected...testing architecture...")

    # on macOS "uname -m" returns the architecture (x86_64 or arm64)
    execute_process(
        COMMAND uname -m
        RESULT_VARIABLE result
        OUTPUT_VARIABLE OSX_NATIVE_ARCHITECTURE
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )

    message("${OSX_NATIVE_ARCHITECTURE}")

    if(OSX_NATIVE_ARCHITECTURE STREQUAL "arm64")
        message("M1/2 chip detected.")
    endif()
endif()

CMake will tell me that it is using x86_64:
CMake 为什么坚持要求使用的处理器是 x86_64,而实际上是 arm64?

What is going on here?

答案1

得分: 2

以下是翻译好的部分:

根据评论发现问题在于提问者仍在使用Intel版本的Homebrew,需要安装ARM版本的Homebrew。切换到ARM版本,然后重新安装之前的软件包。

在Rosetta环境下运行的进程或在任何使用Rosetta的进程下运行的进程将从uname -m报告x86_64

有关更多/相关信息,请参阅:

英文:

As found in the comments, the problem was that the asker was still using the Intel version of Homebrew and needed to install the ARM version of Homebrew. Switch to the ARM version and then reinstall the packages you had before.

A process run with Rosetta or run under any process running with Rosetta will report x86_64 from uname -m.

For more / related info, see:

答案2

得分: 0

根据我上面的评论,问题是我有一个旧版本的Homebrew,其中安装了x86_64 CMake,使用Rosetta。重新安装Homebrew(但首先备份我的已安装包的.txt文件),然后在新Homebrew中重新安装所有我的包解决了我的问题。

请注意,如果你遇到类似的情况,你可能需要更改一些在旧版本Homebrew中设置的路径(即将/usr/local/bin更改为/opt/homebrew/bin)。

英文:

Per my comment above, the problem was that I had an old homebrew that had x86_64 CMake installed with Rosetta. Reinstalling homebrew (but first making a backup .txt of my installed packages) and then reinstalling all my packages within the new homebrew fixed my problem.

Note that, if you're in a similar situation, you may need to change some paths set during old homebrew (i.e. /usr/local/bin to /opt/homebrew/bin)

huangapple
  • 本文由 发表于 2023年4月20日 01:20:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057246.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定