相关疑难解决方法(0)

为什么我在 Apple Silicon 上编译的本机应用程序有时构建为 arm64,有时构建为 x86_64?

我有一个基本的 C 程序:

#include <stdio.h>

int main() {
  printf("Hello, world!\n");
}
Run Code Online (Sandbox Code Playgroud)

当我直接cc在 Apple Silicon 设备上使用它进行编译时,它会生成一个arm64可执行文件:

% cc hello.c -o hello

% file hello
hello: Mach-O 64-bit executable arm64

% ./hello
Hello, world!
Run Code Online (Sandbox Code Playgroud)

但是,当我通过 CMake 或 Ninja 等构建系统构建它时,它会生成 x86_64 二进制文件:

% ./my-build-system

% file hello
hello: Mach-O 64-bit executable x86_64
Run Code Online (Sandbox Code Playgroud)

我已经验证构建脚本运行的命令与我自己运行的命令相同。如果我复制并粘贴该命令并自己运行它,生成的可执行文件仍然是arm64。

c c++ macos native apple-silicon

2
推荐指数
1
解决办法
1507
查看次数

标签 统计

apple-silicon ×1

c ×1

c++ ×1

macos ×1

native ×1