在OS X Lion 10.8.4 x86_64平台搭建C++11开发环境

本文档详细介绍了如何在OS X Lion 10.8.4上搭建C++11开发环境。通过下载并编译GCC 4.8.1,解决依赖问题,以及正确配置环境变量,最终成功构建GCC编译器。过程中提到了避免使用非标准路径安装依赖库以防止动态链接问题,并给出了编译GCC的正确步骤,包括使用./contrib/download_prerequisites脚本简化依赖下载和构建过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2013-08-12 wcdj (明天七夕,纪念结婚一周年)


1 下载最新支持C++11的GCC编译器

http://gcc.gnu.org/

http://gcc.gnu.org/gcc-4.8/(下载gcc 4.8.1)

GCC 4.8.1 will be C++11 feature-complete [2013-04-01] Support for C++11 ref-qualifiers was added to the GCC 4.8 branch, making G++ the first C++ compiler to implement all the major language features of the C++11 standard. This functionality will be available in GCC 4.8.1. (注意并不是所有的新特性都支持)

2 编译遇到的问题

首先查看INSTALL说明:file:///Users/gerryyang/code/public/gcc-4.8.1/INSTALL/index.html,然后尝试编译:

sh-3.2#pwd 

/Users/gerryyang/code/public/gcc-4.8.1


sh-3.2# ./configure --prefix=/usr/local/gcc-4.8.1/
checking build system type... x86_64-apple-darwin12.4.0
checking host system type... x86_64-apple-darwin12.4.0
checking target system type... x86_64-apple-darwin12.4.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking for libatomic support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
checking for the correct version of gmp.h... no
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.
OK,根据错误提示“configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.”下载依赖的packages,ftp路径也已提示我们“ ftp://gcc.gnu.org/pub/gcc/infrastructure/",可以分别从如下链接进行下载:

GMP 4.2+: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2

MPFR 2.4.0+: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2

MPC 0.8.0+: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz

根据提示的顺序分别安装GMP,MPFR和MPC:

step1: ./configure --prefix=/usr/local/gmp-4.3.2; make install
<

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值