xuegy
V2EX  ›  macOS

xcrun c++ 和 clang++ 有什么区别?

By xuegy at 2021 年 6 月 8 日 · 1927 次点击
$ xcrun -l c++
env SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk /Library/Developer/CommandLineTools/usr/bin/c++

$ ls -l /Library/Developer/CommandLineTools/usr/bin/c++
/Library/Developer/CommandLineTools/usr/bin/c++ -> clang
$ clang++ --version
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: arm64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ ls -l /Library/Developer/CommandLineTools/usr/bin/clang++
/Library/Developer/CommandLineTools/usr/bin/clang++ -> clang

编译纯命令行代码。两者都最终指向同一个clang,那么用xcrun这个 wrapper 意义何在?

8 条回复  •  2021-06-08 15:56:59 +08:00
icyalala
   1
icyalala  
   2021 年 6 月 8 日
xcrun 可以指定 sdk 、指定 toolchain,查找工具等等,是 xcode 相关工具。

clang 就只是就只是单纯一个引用,方便你直接使用或者其他构建工具比如 CMake 来用。
你也可以不依赖 xcode 自己装一个 clang 放在那儿。
xuegy
   2
xuegy  
OP
   2021 年 6 月 8 日
@icyalala 如果单纯是一个跨平台的,不依赖 macOS 任何特性的 C++命令行程序,会有什么细微的区别吗?
3dwelcome
   3
3dwelcome  
   2021 年 6 月 8 日
@xuegy "如果单纯是一个跨平台的,不依赖 macOS 任何特性的 C++命令行程序"

clang 都写了 Target: arm64-apple-darwin20.5.0,明显是 apple 定制版本,代码还怎么跨平台。除非只编译 hello world 或者 LLVM 中间汇编语言去二次转换。

clang++在其他平台上,也需要 wrapper 来指定用哪个版本的 windows sdk 或者头文件路径。

单独一个没有头文件路径和编译环境的 clang,是没有灵魂的。
xuegy
   4
xuegy  
OP
   2021 年 6 月 8 日 via iPhone
@3dwelcome 源代码是跨平台的,没毛病啊。
3dwelcome
   5
3dwelcome  
   2021 年 6 月 8 日
@xuegy 你又不可能一直写控制台程序的。正常的程序都有 UI 界面,这就不是跨平台的了。

QT 这种所谓跨平台,也只不过把平台相关的 API 抽象出来罢了。
xuegy
   6
xuegy  
OP
   2021 年 6 月 8 日 via iPhone
@3dwelcome 就一个纯数值计算程序,确实是没有 UI…
agagega
   7
agagega  
   2021 年 6 月 8 日 via iPhone
你还可以直接用 c++这个命令
xylxAdai
   8
xylxAdai  
   2021 年 6 月 8 日
就单纯的命令行代码。。那确实没有意义,只是看你需不需要平台相关的自动查找路径和预编译头编译参数之类的东西
© 2026 V2EX · 34ms · 3.9.8.5