xcode - Mac os x/usr/bin/gcc 文件

标签 xcode macos gcc osx-mavericks

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

它工作正常,但使用它的命令是 gcc-4.9和 CMake 调用 cc命令。于是我搜了一下,发现/usr/bin/cc是指向 /usr/bin/clang 的符号链接(symbolic link).我决定把它改成/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.

但它不是符号链接(symbolic link)...这是 ls -l 的结果命令 :
-rwxr-xr-x   1 root   wheel     14224 23 oct 07:40 gcc

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

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

谢谢 :)

最佳答案

Apple 似乎使用 xcode-select 重定向了一些常见的开发人员命令行工具。二进制。 /usr/bin/gcc 而不是符号链接(symbolic link)调用一个小的二进制文件,它可以选择 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
关于该主题的一些文章:
  • https://macops.ca/developer-binaries-on-os-x-xcode-select-and-xcrun/
  • https://randomtechnicalstuff.blogspot.com/2016/05/os-x-and-xcode-doing-it-apple-way.html
  • 关于xcode - Mac os x/usr/bin/gcc 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20663695/

    相关文章:

    objective-c - iPad 应用程序。退出(0)留在 'taskbar'

    objective-c - 在 NSOutlineView 中为 "sliding"设置动画

    c - macOS 上的 gettimeofday() 是否使用系统调用?

    c - Gcc 使用 sqrt 而不包含 math.h

    c - 带有gcc的segger嵌入式工作室中的 volatile 变量

    xcode - 暂停函数直到用户输入

    ios - 在哪里存储局部变量? NSKeyedArchiver 还是 NSUserDefaults?

    c - 为什么 OS X 上的 fgets 输出一个 BELL (^G, ascii : 07) character when input exceeds expected length?

    Sierra 上的 Eclipse 窗口重定位

    c - 如何使用共享库中的方法