Mac os x /usr/bin/gcc file

Viewed 1072

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).

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...

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.

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

(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 !

Thanks :)

1 Answers

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.

From the man page:

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.

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:

Related