Homebrew没有将gcc 5.3链接到/ 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被破坏,而是在ElCapitán下,默认情况下,gcc(5.2和5.3)和ld都不搜索/ usr / local / lib和/ usr / local / include。 它们必须分别显式包含在环境变量LIBRARY_PATH和CPLUS_INCLUDE_PATH中。 另外,ld不是gnu版本,因此忽略LD_LIBRARY_PATH。 以下是代码。 由于它是(我希望)是一次性脚本,因此我对一些变量进行了硬编码,这些变量可能是命令行选项以供更通用的用途。

让我知道,如果代码不清楚(不会让我感到惊讶)

#!/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不会将gcc安装为gcc ,而是gcc-5 ,为了避免冲突 ,所以请注意,以不同的方式进行并改变事情是潜在的秘密。

一些可能的解决方

  • 使用命令brew link gcc

    ↳OSX - 用通过Homebrew安装的版本替换gcc版本

  • 创建符号链接

    ↳如何在Linux中符号链接文件?

  • 阅读文档以获取有关编辑/修改默认设置的提示

    ↳自制软件常见问题

  • 第一个也是最后一个选项可能是更明智的路线,但也许这不是您要查找的内容......该文档将帮助您了解为什么他们按照他们的方式完成了这个任务。

    链接地址: http://www.djcxy.com/p/78079.html

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

    下一篇: Installing Julia v0.5 on Ubuntu 16.04 while v0.6 is installed