关于macos:Homebrew没有将gcc 5.3链接到/ usr / local / bin / gcc(OS X 10.11.4 El Capitan)

Homebrew does not link gcc 5.3 to /usr/local/bin/gcc (OS X 10.11.4 El Capitan)

我刚把我的Mac Book Pro更新为El Capitan(10.11.4),GCC 5.2坏了,所以我使用自制安装了GCC 5.3.0,但新的编译器没有链接到/usr/local/bin/gcc。相反,它与/usr/local/bin/gcc-5相连。同样,所有相关的命令(g++,gcc ar,gcc ranlib,…)现在都附加了"-5",而普通gcc系列w/o"-5"仍然链接到5.2。

有没有办法强迫自制连接到普通GCC?


现在我安装了5.3,我不再需要5.2了。但是,将5.3链接重新链接到'-5'名称,因此我使用一个简短的Perl脚本将5.3版链接到普通的gcc(即不带'-5'后缀)。我发现问题并不是GCC 5.2坏了,而是在el capit_n下,GCC(5.2&5.3)和ld默认不搜索/usr/local/lib和/usr/local/include。它们必须分别明确地包含在环境变量库_path和cplus_include_path中。此外,ld不是GNU版本,因此忽略ld_库_路径。下面是代码。因为它是(我希望)一个一次性的脚本,所以我硬编码了一些变量,这些变量可能是命令行选项,以便更广泛地使用。

如果代码不清楚,请告诉我(我不会感到惊讶)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/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'
";


my $new_darwin_version ="15.4.0";

foreach my $file (@gcc_5_list){
    if (! -l $file){
        print"$file is not a symbolic link
";
        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 link
";
        next;
    }
# ..File pointed to by '$file'
    my $orig = readlink($file);
# # #     print"$file -> $orig
";

# __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!
";
        next;
    }
# ..If the '$plain' file exists, remove it before linking
    if (-e $plain ){
# # #         print"\tWould remove $plain
";
# # #         print"\tunlink $plain
";
        unlink $plain;
    }
    else {
# # #         print"\t$plain does not exist would create
";
    }
# ..Finally! link the new version
    symlink $orig, $plain;

}


为了避免冲突,自制啤酒不安装gcc,而安装gcc,而是安装gcc-5,因此要注意,以不同的方式进行和改变是一个可能的解决问题的方法。

一些可能的解决方案:

  • 使用命令brew link gcc

    ?OSX-用通过自制安装的版本替换GCC版本

  • 创建符号链接

    ?如何在Linux中对文件进行符号链接?

  • 阅读文档了解有关编辑/修改默认值的提示

    ?家庭酿出常见问题解答

  • 第一个也是最后一个选择可能是更明智的路线,但也许这不是你想要的……这些文档将帮助您理解他们为什么会这样做。