我有一个基本的 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。