V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
xuegy
V2EX  ›  macOS

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

  •  
  •   xuegy · Jun 8, 2021 · 1541 views
    This topic created in 1784 days ago, the information mentioned may be changed or developed.
    $ 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 replies    2021-06-08 15:56:59 +08:00
    icyalala
        1
    icyalala  
       Jun 8, 2021
    xcrun 可以指定 sdk 、指定 toolchain,查找工具等等,是 xcode 相关工具。

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

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

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

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

    QT 这种所谓跨平台,也只不过把平台相关的 API 抽象出来罢了。
    xuegy
        6
    xuegy  
    OP
       Jun 8, 2021 via iPhone
    @3dwelcome 就一个纯数值计算程序,确实是没有 UI…
    agagega
        7
    agagega  
       Jun 8, 2021 via iPhone
    你还可以直接用 c++这个命令
    xylxAdai
        8
    xylxAdai  
       Jun 8, 2021
    就单纯的命令行代码。。那确实没有意义,只是看你需不需要平台相关的自动查找路径和预编译头编译参数之类的东西
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   994 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 20:12 · PVG 04:12 · LAX 13:12 · JFK 16:12
    ♥ Do have faith in what you're doing.