V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xuegy
V2EX  ›  macOS

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

  •  
  •   xuegy · 2021-06-08 12:47:40 +08:00 · 1095 次点击
    这是一个创建于 1077 天前的主题,其中的信息可能已经有所发展或是发生改变。
    $ 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-06-08 12:58:00 +08:00
    xcrun 可以指定 sdk 、指定 toolchain,查找工具等等,是 xcode 相关工具。

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

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

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

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

    QT 这种所谓跨平台,也只不过把平台相关的 API 抽象出来罢了。
    xuegy
        6
    xuegy  
    OP
       2021-06-08 14:24:35 +08:00 via iPhone
    @3dwelcome 就一个纯数值计算程序,确实是没有 UI…
    agagega
        7
    agagega  
       2021-06-08 14:38:57 +08:00 via iPhone
    你还可以直接用 c++这个命令
    xylxAdai
        8
    xylxAdai  
       2021-06-08 15:56:59 +08:00
    就单纯的命令行代码。。那确实没有意义,只是看你需不需要平台相关的自动查找路径和预编译头编译参数之类的东西
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1033 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:23 · PVG 03:23 · LAX 12:23 · JFK 15:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.