【问题标题】:Mac os x /usr/bin/gcc fileMac os x /usr/bin/gcc 文件
【发布时间】:2014-01-06 23:00:52
【问题描述】:

我使用的是 Mac OS X 10.9 (Mavericks)。我最近不得不使用 CMake 和 OpenMP 库编译代码。所以一开始我用xcode-select --install 下载了XCode 命令行工具。这是问题所在:XCode 使用不带 OpenMP 的 clang 编译器。所以我得到了gcc-4.9brew 包管理器(GCC 有OpenMP 库)。

它工作正常,但使用它的命令是gcc-4.9,CMake 调用cc 命令。所以我搜索了一下,发现/usr/bin/cc 是指向/usr/bin/clang 的符号链接。我决定把它改成/usr/bin/gcc,但问题来了:我不知道这个文件是什么...

它看起来像 clang 命令文件:如果我不带任何参数运行它,我会得到 clang 错误而不是 gcc 错误:

$ gcc
clang: error: no input files
$ gcc-4.9
gcc-4.9: fatal error: no input files
compilation terminated.

但它不是符号链接...这是ls -l 命令的结果:

-rwxr-xr-x   1 root   wheel     14224 23 oct 07:40 gcc

(好像是我升级小牛时创建的) 对于 g++ 来说也是一样的。 它是 clang 的一种副本,具有不同的名称吗?为什么 Apple 不使用符号链接?

因此,如果这里有人知道我是否可以删除这些文件以放置符号链接而不会有任何问题(或更好的解决方案),请告诉我!

谢谢:)

【问题讨论】:

    标签: xcode macos gcc osx-mavericks


    【解决方案1】:

    Apple 似乎使用 xcode-select 二进制文件重定向了一些常见的开发人员命令行工具。 /usr/bin/gcc 不是符号链接,而是调用一个小的二进制文件,该二进制文件可以根据一些环境变量选择不同版本的gcc

    来自手册页:

    xcode-select  controls  the location of the developer directory used by
    xcrun(1), xcodebuild(1), cc(1), and other  Xcode  and  BSD  development
    tools. This also controls the locations that are searched for by man(1)
    for developer tool manpages.
    
    This allows you to easily switch  between  different  versions  of  the
    Xcode  tools  and  can be used to update the path to the Xcode if it is
    moved after installation.
    
    ...
    
    After setting a developer directory, all of the  xcode-select  provided
    developer  tool shims (see FILES) will automatically invoke the version
    of the tool inside the selected developer directory.
    

    我们可以通过查看二进制文件来确认(这是来自 OS 10.14.6):

    $ otool -tvV /usr/bin/gcc
    
    /usr/bin/gcc:
    (__TEXT,__text) section
    _main:
    0000000100000f77    pushq   %rbp
    0000000100000f78    movq    %rsp, %rbp
    0000000100000f7b    leal    -0x1(%rdi), %eax
    0000000100000f7e    leaq    0x8(%rsi), %rdx
    0000000100000f82    leaq    0x29(%rip), %rdi ## literal pool for: "gcc"
    0000000100000f89    xorl    %ecx, %ecx
    0000000100000f8b    movl    %eax, %esi
    0000000100000f8d    callq   0x100000f92 ## symbol stub for: _xcselect_invoke_xcrun
    

    关于该主题的一些文章:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-19
      • 2012-03-11
      • 2016-07-21
      • 2011-05-21
      • 2015-12-30
      • 2015-02-03
      • 2013-06-10
      • 2016-01-22
      相关资源
      最近更新 更多