Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

macos - Install GNU GCC on mac

I have recently become frustrated with the new clang compiler included with Xcode 5. I was wondering what the best way to install GNU GCC on OS X would be.

Things to consider:

  • I don't want to use MacPorts, fink, homebrew or any other third party package manager.
  • I would like to use the latest GCC, compiled from source, if possible.
  • I need the existing GCC (hardlink to clang) to remain the default, but to easily be able to use GNU GCC when I need to.
  • I would like to avoid modifying the code if at all possible.

EDIT: Success! Using GCC 4.9.2 (with GMP 5.1.3, MPFR 3.1.2, MPC 1.0.2, ISL 0.12.2, and CLooG 0.18.1) I succesfully built GCC. Tips to take from here:

  • Make sure you use ISL and CLooG. Yes, they are optional, but they make a more optimised compiler and I had trouble building without them. Make sure you use ISL 0.12, not the latest version (0.14).
  • If possible, use the standalone Developer Tools, not XCode. (XCode has some buggy headers, and while I didn't notice any issues building GCC I have had issues with other software (e.g. GPG)).
  • I recommend putting all your sources in the gcc directory, rather than building and installing separately (it's faster this way)
  • Make sure you invoke configure with CC=clang CXX=clang++ so GCC knows it isn't being compiled by GCC.
  • Definitely, definitely, definitely, invoke make with -j8, or otherwise the build will take about 4 hours! (With -j8, it took 1 1/3 hours on my Mid-2012 MBP with 8gb RAM.) (make -j8 means make can build 8 threads simultaneously (4 cores + HT), whereas on a 2-core machine you would run make -j4.)

Hope this helps!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Homebrew now has the GCC package so you can install it with this command:

brew install gcc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...