error: command 'gcc' failed with exit status 1


MacOS下想安裝MySQL-Python,執行語句:

sudo pip install MySQL-Python

遇到了如下錯誤信息:

/Users/kaitlyn/anaconda3/envs/env2.7/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/include-fixed/limits.h:168:61: fatal error: limits.h: No such file or directory

     #include_next <limits.h>  /* recurse down to the real one */

                                                                 ^

    compilation terminated.

    error: command 'gcc' failed with exit status 1

 

可以看到gcc缺少頭文件limit.h,google上看到有一個人遇到了相同的問題,他更新了新版本的gcc,問題得以解決。

 

解決方案是:更新gcc

 

1、下載適用於你的系統的MacPort,地址為https://www.macports.org/install.php

  我的系統是macOS Mojave,所以下載安裝macOS Mojave v10.14

2、更新MacPort版本,確保是最新版,在命令行輸入:

sudo port selfupdate

3、安裝gcc,在命令行輸入:

sudo port install gcc7

  然后等待安裝,過程可能比較慢。我安裝的是gcc7,如果想安裝任意別的版本,比如版本x,可以輸入gccx。

  在執行這條語句時這里遇到一個問題:

  Warning: xcodebuild exists but failed to execute

  Warning: Xcode does not appear to be installed; most ports will likely fail to build.

  

  原因是從xcode4.3之前的版本更新之后,xcode-select依然指向舊版的xcode,需要在命令行輸入:

 

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

 

  這個辦法我是參考的鏈接https://trac.macports.org/wiki/ProblemHotlist,finish這條命令以后再sudo port install gcc7安裝一下。

 

4、我使用下面的命令更新了gcc7的最新版,當然這一步你也可以跳過

sudo port -n upgrade --force gcc7

(env2.7) Kaitlyns-Mac:lib kaitlyn$ sudo port -n upgrade --force gcc7

--->  Fetching archive for gcc7

--->  Attempting to fetch gcc7-7.4.0_0.darwin_18.x86_64.tbz2 from https://pek.cn.packages.macports.org/macports/packages/gcc7

--->  Attempting to fetch gcc7-7.4.0_0.darwin_18.x86_64.tbz2.rmd160 from https://pek.cn.packages.macports.org/macports/packages/gcc7

--->  Computing dependencies for gcc7

--->  Deactivating gcc7 @7.4.0_0

--->  Cleaning gcc7

--->  Uninstalling gcc7 @7.4.0_0

--->  Cleaning gcc7

--->  Computing dependencies for gcc7

--->  Installing gcc7 @7.4.0_0

--->  Activating gcc7 @7.4.0_0

--->  Cleaning gcc7

--->  Scanning binaries for linking errors

--->  No broken files found.

--->  No broken ports found.

5、安裝完成以后,輸入gcc -version查看現在的版本,發現依然是以前的舊版本4.8.5,而不是我安裝的新版本7。

(env2.7) Kaitlyns-Mac:lib kaitlyn$ gcc --version

gcc (GCC) 4.8.5

Copyright (C) 2015 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  這是因為原始默認版本就是4.8.5,需要切換版本。

  切換版本:你可以下面的語句查看MacPort管理所有版本。以mp作為前綴開頭的是MacPort自己管理的版本,而gcc7和IIvm-gcc7是Xcode管理的。

port select --list gcc

(env2.7) Kaitlyns-Mac:bin kaitlyn$ port select --list gcc

Available versions for gcc:

mp-gcc7

none (active)

  可以看見我安裝新版mp-gcc7

設置它為默認:

sudo port select --set gcc mp-gcc7

(env2.7) Kaitlyns-Mac:bin kaitlyn$ sudo port select --set gcc mp-gcc7

Password:

Selecting 'mp-gcc7' for 'gcc' succeeded. 'mp-gcc7' is now active.

再查看:

gcc --version

(env2.7) Kaitlyns-Mac:bin kaitlyn$ gcc --version

gcc (MacPorts gcc7 7.4.0_0) 7.4.0

Copyright (C) 2017 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

可以看到現在為gcc7.4.0了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM