Mac OS X /usr/bin/gcc 文件

6
我使用的是Mac OS X 10.9 (Mavericks)操作系统。最近我需要用CMake和OpenMP库编译代码。所以,我首先下载了带有xcode-select --install命令行工具的XCode。问题在于:XCode使用的是clang编译器,它不支持OpenMP。因此,我通过brew包管理器获取了gcc-4.9(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

(似乎是在我升级到Mavericks时创建的) 对于g ++也完全一样。 它是clang的某种副本,名称不同吗?为什么苹果不使用符号链接?

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

谢谢:)

1个回答

0

看起来,苹果公司使用 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

关于该主题的一些文章:


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接