Homebrew does not link gcc 5.3 to /usr/local/bin/gcc (OS X 10.11.4 El Capitan)
I just updated my Mac Book Pro to El Capitan (10.11.4) and gcc 5.2 broke, so I installed gcc 5.3.0 using homebrew but the new compiler is not linked to /usr/local/bin/gcc
. Instead it's linked to /usr/local/bin/gcc-5
. Likewise, all the related commands (g++, gcc-ar, gcc-ranlib, ...) have now the '-5' appended whereas the plain gcc family w/o '-5' is still linked to 5.2.
Is there a way to force homebrew to link to plain gcc?
Now that I installed 5.3, I don't need 5.2 anymore. However, re-linking 5.3 links to the '-5' names, so I ended using a short Perl script to link version 5.3 to plain gcc (ie w/o the '-5' suffix). I found that the problem was not that gcc 5.2 was broken but instead, under El Capitán, gcc (both 5.2 & 5.3) and ld do not search /usr/local/lib and /usr/local/include by default. They have to be explicitly included in the environment variables LIBRARY_PATH and CPLUS_INCLUDE_PATH, respectively. In addition, ld is not the gnu version and thus ignores LD_LIBRARY_PATH. Below is the code. Since it was (I hope) a single-use script, I hard-coded some variables that could be command-line options for more general use.
Let me know if the code is unclear (would not surprise me)
#!/usr/bin/perl
# relink_gcc unlinks the old gcc and links the current version
#
# SYNOPSIS:
# cd /usr/local/bin
# relink_gcc
#
# DESCRIPTION:
# Homebrew installs gcc version 5.X as gcc-5. All other components
# of the Gnu Compiler Collection are installed with the '-5' suffix.
# E.g. g++-5, c++-5, ... However, I prefer to have the names w/o
# the '-5' suffix so I can use the same Makefiles on different
# computers. This program changes the links from the plain gcc
# (and its family) to point to the most recent gcc version.
# Because 'darwin' also changes version, the program changes the
# version of programs with 'darwin' in their names to the current
# version. The gcc and darwin versions are currently hardcoded.
#
# CAVEAT:
# Make a backup of /usr/local/bin and /usr/local/Cellar before
# using this script
use strict;
use warnings;
my @gcc_5_list = glob('*-5');
print "found $#gcc_5_list files ending in '-5'n";
my $new_darwin_version = "15.4.0";
foreach my $file (@gcc_5_list){
if (! -l $file){
print "$file is not a symbolic linkn";
next;
}
my $plain = $file;
# ..Get rid of the '-5' at the end
$plain =~ s/-5$//;
# ..If the file exists but is not a link, leave it alone.
if (-e $plain && (! -l $plain )){
print "$plain is not a linkn";
next;
}
# ..File pointed to by '$file'
my $orig = readlink($file);
# # # print "$file -> $orign";
# __Change versions to current ones
# ..Gnu compiler collection version
$orig =~ s/5.2.0/5.3.0/g;
# ..Apple Darwin version
$orig =~ s/(darwin)d{2}.d.d/$1$new_darwin_version/;
# ..Skip non-existent files
if (! -e $orig){
print "t$orig does not exist. Skip!n";
next;
}
# ..If the '$plain' file exists, remove it before linking
if (-e $plain ){
# # # print "tWould remove $plainn";
# # # print "tunlink $plainn";
unlink $plain;
}
else {
# # # print "t$plain does not exist would createn";
}
# ..Finally! link the new version
symlink $orig, $plain;
}
Homebrew does not install gcc
as gcc
, but as gcc-5
, to avoid conflicts , so be advised that going and changing things around differently is a potential recipe for mucking things up.
Some possible solutions:
Use the command brew link gcc
↳ OSX - replace gcc version with version installed via Homebrew
Create symbolic links
↳ How to symlink a file in Linux?
Read the documentation for tips on editing/modifying defaults
↳ Homebrew FAQ
The first and last option is likely the more sensible route, but maybe that's not what you're looking for... The documentation will help you understand why they've done it the way they have.
链接地址: http://www.djcxy.com/p/78080.html下一篇: Homebrew没有将gcc 5.3链接到/ usr / local / bin / gcc(OS X 10.11.4 El Capitan)