mac上gcc的安装(转自网络)

Suppose you want to use the latest and greatest version of GCC on the Mac because you want to use features in C++11 that are not yet available in XCode. There are probably a few ways to do this, but one way is via MacPorts which provides precompiled binaries for tons of packages.

You can follow the following steps to install GCC 4.7 via MacPorts. Others versions (including GCC 4.8) follow a pretty similar procedure.

Browse to the MacPorts website. Download the DMG image for your operating system

Install the package

Open up a terminal

Applications > Utilities > Terminal
Make sure that you have the latest version by running the self update via the terminal command

sudo port selfupdate

Install GCC via the terminal command

sudo port install gcc47

Now sit back and wait while MacPorts does its thing. One MacPorts is done, the next thing is to compile a simple program. Running gcc or g++ at the command line invokes the compiler installed with XCode. The new executables are installed to

/opt/local/bin/gcc-mp-4.7

and

/opt/local/bin/g++-mp-4.7

Depending on your build environment, you may want to access GCC by running gcc or g++ at the command line. Because the MacPorts are installed to another location, you either need to either specify the full path, or set the compiler to use on your system. For the second option, you can use MacPorts to select the default compiler. First, identify which versions are installed on your system.

port select --list gcc

In my case, this returns

Available versions for gcc:
   gcc42
   llvm-gcc42
   mp-gcc47
   none (active)

To select GCC 4.7, run the command

sudo port select --set gcc mp-gcc47
Password:
Selecting 'mp-gcc47' for 'gcc' succeeded. 'mp-gcc47' is now active.

原文链接: https://www.cnblogs.com/yuehq/p/5164529.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    mac上gcc的安装(转自网络)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/228109

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 下午1:49
下一篇 2023年2月13日 下午1:50

相关推荐