首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >自制软件不会将gcc 5.3链接到/usr/local/bin/gcc (OS X 10.11.4 El Capitan)

自制软件不会将gcc 5.3链接到/usr/local/bin/gcc (OS X 10.11.4 El Capitan)
EN

Stack Overflow用户
提问于 2016-04-02 06:06:04
回答 2查看 4.2K关注 0票数 3

我刚刚更新了我的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‘,而没有'-5’的朴素的gcc家族仍然与5.2联系在一起。

有没有办法强制自制软件链接到朴素的gcc?

EN

回答 2

Stack Overflow用户

发布于 2016-04-08 01:30:59

代码语言:javascript
运行
复制
    #!/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 N.X as gcc-N. All other components
    #   of the Gnu Compiler Collection are installed with the '-N' suffix.
    #   E.g. g++-N, c++-N, ... However, I prefer to have the names w/o
    #   the '-N' 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;
    
    # Set parameters here. I might add command line args at some point.
    #..Dry run only prints what would be done. Does not actually do it.
    my $dryrun = 1;

    my $new_version = 10; 
    my $ending = "-$new_version";
    my $re_ending = qr/$ending/;
    
    # ..In case upgrading one sub-version to another (e.g. 5.2.0 to 5.3.1)
    #   (moot if upgrading to new version (e.g. 5.N.M to 6.K.L)
    my $old_sub = qr/5\.2\.0/;
    my $new_sub = qr/$new_version\.2\.0/;
    # ..To find the Darwin version, at the command line prompt enter
    #       uname -r
    my $new_darwin_version = "17.7.0";
    
    
    
    # No changes needed below this line (I hope)
    
    my @gcc_N_list = glob qq("*${ending}");
    
    print "found $#gcc_N_list files ending in '$ending'\n";
# ..If the file exists but is not a link, leave it alone.
    if (-e $plain && (! -l $plain )){ 
        print "$plain is not a link\n";
        next;
    }   
# ..File pointed to by '$file'
    my $orig = readlink($file);
    if ($dryrun) {print "$file -> $orig\n";}

# __Change versions to current ones if sub-version upgrade
# ..Gnu compiler collection version
    $orig =~ s/${old_sub}/${new_sub}/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;
    }
# ..Remove existing files before linking
    if (-e $plain || -l $plain ){
        print "$plain exists\n";
        if ($dryrun) {
            print "\tWould remove $plain\n";
            print "\tunlink $plain\n";
        }
        else {
            unlink $plain or die "Unable to unlink $plain $!\n";
        }
    }
    else {
        print "\t$plain does not exist would create\n";
    }
# ..Finally! link the new version
    if ($dryrun) {
        print "\twould symlink $orig, $plain;\n";
    }
    else {
        symlink $orig, $plain
            or die "Unable to symlink $orig to $plain:$!\n";
    }

}
票数 1
EN

Stack Overflow用户

发布于 2016-04-02 06:59:09

为了避免冲突**,Homebrew没有将 gcc-5**安装为 gcc,,而是安装为**,因此请注意,以不同的方式改变事物可能会把事情搞砸。

一些可能的解决方案:

  1. 使用命令brew link gcc

OSX - replace gcc version with version installed via Homebrew

  1. 创建符号链接

How to symlink a file in Linux?

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

Homebrew FAQ

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36366562

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档