Mac OS X/usr/bin/gcc文件 [英] Mac os x /usr/bin/gcc file

查看:100
本文介绍了Mac OS X/usr/bin/gcc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Mac OS X 10.9 (Mavericks). I recently had to compile code using CMake and OpenMP library. So at first I downloaded XCode Command line tools with xcode-select --install. Here's the problem : XCode uses clang compiler which doesn't bring OpenMP. So I got gcc-4.9 with brew package manager (GCC has the OpenMP library).

它可以正常工作,但是使用它的命令是 gcc-4.9 ,并且CMake调用 cc 命令.因此,我进行了搜索,发现/usr/bin/cc /usr/bin/clang 的符号链接.我决定将其更改为/usr/bin/gcc ,但这是问题所在:我不知道这个文件是什么...

It works fine, but the command to use it is gcc-4.9 and CMake calls the cc command. So I searched, and found out that /usr/bin/cc was a symbolic link to /usr/bin/clang. I decided to change it to /usr/bin/gcc, but here's the problem : I don't know what this file is...

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

It looks like the clang command file : if I run it without any argument, I get the clang error instead of a gcc error :

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

但这不是符号链接...这是 ls -l <​​/code>命令的结果:

But it isn't a symbolic link... Here's the result of a ls -l command :

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

(似乎是我对Mavericks进行升级时创建的)对于g ++来说,这是完全一样的.它是一种clang副本,具有不同的名称吗?苹果为什么不使用符号链接?

(seems like it was created when I did the Mavericks upgrade) And it's exactly the same thing for g++. Is it a sort of copy of clang, with a different name ? Why isn't Apple using a symbolic link ?

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

So if anyone here knows if I can delete these files to put a symbolic link instead without any problem (or a better solution), let me know !

谢谢:)

推荐答案

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

It appears that Apple redirects some common developer command-line tools using the xcode-select binary. Instead of a symlink, /usr/bin/gcc invokes a small binary that can select different versions of gcc according to some environment variables.

在手册页中:

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)进行确认:

We can confirm by looking at the binary (this is from 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

有关该主题的一些文章:

Some articles on the topic:

这篇关于Mac OS X/usr/bin/gcc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆