Build a C ++ 11 development environment on the OS X lion 10.8.4 x86_64 Platform

Source: Internet
Author: User
Tags gmp hosting sites gfortran

20130812 wcdj)

1. Download the GCC compiler that supports C ++ 11.

Http://gcc.gnu.org/

Http://gcc.gnu.org/gcc-4.8/ (download GCC 4.8.1)

GCC 4.8.1 will BEC ++ 11 feature-complete [2013-04-01]
Support for C ++ 11 Ref-qualifiersWas 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. (Not all new features are supported)
2 problems encountered during compilation

First check install Description: file: // users/gerryyang/code/public/gcc-4.8.1/install/index.html, and then try to compile:

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.0checking host system type... x86_64-apple-darwin12.4.0checking target system type... x86_64-apple-darwin12.4.0checking for a BSD-compatible install... /usr/bin/install -cchecking whether ln works... yeschecking whether ln -s works... yeschecking for a sed that does not truncate output... /usr/bin/sedchecking for gawk... nochecking for mawk... nochecking for nawk... nochecking for awk... awkchecking for libatomic support... yeschecking for libitm support... yeschecking for libsanitizer support... yeschecking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables... checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for g++... g++checking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking whether g++ accepts -static-libstdc++ -static-libgcc... nochecking for gnatbind... nochecking for gnatmake... nochecking whether compiler driver understands Ada... nochecking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2checking for objdir... .libschecking for the correct version of gmp.h... noconfigure: 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 specifytheir locations.  Source code for these libraries can be found attheir respective hosting sites as well as atftp://gcc.gnu.org/pub/gcc/infrastructure/.  See alsohttp://gcc.gnu.org/install/prerequisites.html for additional info.  Ifyou obtained GMP, MPFR and/or MPC from a vendor distribution package,make sure that you have installed both the libraries and the headerfiles.  They may be located in separate packages.

OK. According to the error message "Configure: Error: Building GCC requires GMP 4.2 +, mpfr 2.4.0 + and MCM 0.8.0 +. "Download dependent packages, FTP path also prompts us" ftp://gcc.gnu.org/pub/gcc/infrastructure/ ", can be downloaded from the following link respectively:

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

MCM 0.8.0 +:
Ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz

Follow the prompts to install GMP, mpfr, and MCM:

Step 1:./configure -- prefix =/usr/local/gmp-4.3.2; make install

Step 2:./configure -- prefix =/usr/local/mpfr-2.4.2 -- With-GMP =/usr/local/gmp-4.3.2/; make install

Note: Step 2 depends on Step 1. Otherwise, an error "Configure: Error: GMP. h can't be found, or is unusable." is reported.

Step 3 :. /configure -- prefix =/usr/local/mpc-0.8.1 -- With-GMP =/usr/local/gmp-4.3.2/-- With-mpfr =/usr/local/mpfr-2.4.2/; make install

Note: Step 3 also depends on the previous database. Otherwise, "Configure: Error: libgmp not found or uses a different Abi" is reported. and configure: Error: libmp fr not found or uses a different Abi. "error.

Step 4: Set the environment variable, export LD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/gmp-4.3.2/lib/:/usr/local/mpfr-2.4.2/lib /: /usr/local/mpc-0.8.1/lib/

Step 5 :. /configure -- prefix =/usr/local/gcc-4.8.1/-- enable-threads = POSIX -- disable-checking -- With-GMP =/usr/local/gmp-4.3.2/-- With-mpfr =/ usr/local/mpfr-2.4.2/-- With-MPC =/usr/local/mpc-0.8.1/(or prompt not to find it! Seems to have fallen into the trap)

3. Correct Compilation Method

The above method is not recommended in reference to [2:

The difficult way, which isNot recommended, Is to download the sources for GMP, mpfr and MPC, then configure and install each of them in non-standard locations, then configure GCC-- With-GMP =/Some/silly/path/GMP -- With-mpfr =/Some/silly/path/mpfr -- With-MPC =/Some/silly/path/MPC,
Then be forced to setLD_LIBRARY_PATH =/Some/silly/path/GMP:/Some/silly/path/mpfr:/Some/silly/path/MPC/libIn your environment forever. This is silly and causes major problems for anyone who doesn't understand how dynamic linkers find
Libraries at runtime. Do not do this. If building GCC fails when using any of-- With-GMPOr-- With-mpfrOr-- With-MPCOptions then you probably shouldn't be using them.

Refer to [2] to introduce a simpler method:

Alternatively, after extracting the GCC source archive, simply run
./Contrib/download_prerequisitesScript in the GCC source directory. That will download the support libraries and create symlinks, causing them to be built automatically as part of the GCC build process. SetGraphite_loop_opt = Yes
In the script if you want to build GCC with the graphite loop optimizations.

# gcc-4.8.1/contrib/download_prerequisites# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU# General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see http://www.gnu.org/licenses/.MPFR=mpfr-2.4.2GMP=gmp-4.3.2MPC=mpc-0.8.1wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1tar xjf $MPFR.tar.bz2 || exit 1ln -sf $MPFR mpfr || exit 1wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1tar xjf $GMP.tar.bz2  || exit 1ln -sf $GMP gmp || exit 1wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1tar xzf $MPC.tar.gz || exit 1ln -sf $MPC mpc || exit 1rm $MPFR.tar.bz2 $GMP.tar.bz2 $MPC.tar.gz || exit 1

Before downloading wget (use the source code, there are some "pitfalls" here. If -- With-SSL = OpenSSL is not specified, the system prompts you to install gnutls)

...checking for compress in -lz... yeschecking for gpg_err_init in -lgpg-error... nochecking for gcry_control in -lgcrypt... nochecking for libgnutls... noconfigure: error: --with-ssl was given, but GNUTLS is not available.

Note the with-SSL = OpenSSL option in the command above. If you omit that, you will get the following error:

Download wget source code:
Http://www.gnu.org/software/wget/
Tar-xzvf wget-1.14.tar.gz
CD wget-1.14
./Configure -- With-SSL = OpenSSL
Make
Sudo make install

After wget is installed, use the script in the code to download the GCC dependent files:

sh-3.2# pwd/Users/gerryyang/code/public/gcc-4.8.1sh-3.2# ./contrib/download_prerequisites--2013-08-12 22:37:39--  ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2           => ‘mpfr-2.4.2.tar.bz2’Resolving gcc.gnu.org... 209.132.180.131Connecting to gcc.gnu.org|209.132.180.131|:21... connected.Logging in as anonymous ... Logged in!==> SYST ... done.    ==> PWD ... done.==> TYPE I ... done.  ==> CWD (1) /pub/gcc/infrastructure ... done.==> SIZE mpfr-2.4.2.tar.bz2 ... 1077886==> PASV ... done.    ==> RETR mpfr-2.4.2.tar.bz2 ... done.Length: 1077886 (1.0M) (unauthoritative)100%[==================================================================================================================================================================>] 1,077,886    194KB/s   in 5.7s   2013-08-12 22:37:51 (185 KB/s) - ‘mpfr-2.4.2.tar.bz2’ saved [1077886]--2013-08-12 22:37:51--  ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2           => ‘gmp-4.3.2.tar.bz2’Resolving gcc.gnu.org... 209.132.180.131Connecting to gcc.gnu.org|209.132.180.131|:21... connected.Logging in as anonymous ... Logged in!==> SYST ... done.    ==> PWD ... done.==> TYPE I ... done.  ==> CWD (1) /pub/gcc/infrastructure ... done.==> SIZE gmp-4.3.2.tar.bz2 ... 1897483==> PASV ... done.    ==> RETR gmp-4.3.2.tar.bz2 ... done.Length: 1897483 (1.8M) (unauthoritative)100%[==================================================================================================================================================================>] 1,897,483    177KB/s   in 10s    2013-08-12 22:38:08 (177 KB/s) - ‘gmp-4.3.2.tar.bz2’ saved [1897483]--2013-08-12 22:38:09--  ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz           => ‘mpc-0.8.1.tar.gz’Resolving gcc.gnu.org... 209.132.180.131Connecting to gcc.gnu.org|209.132.180.131|:21... connected.Logging in as anonymous ... Logged in!==> SYST ... done.    ==> PWD ... done.==> TYPE I ... done.  ==> CWD (1) /pub/gcc/infrastructure ... done.==> SIZE mpc-0.8.1.tar.gz ... 544950==> PASV ... done.    ==> RETR mpc-0.8.1.tar.gz ... done.Length: 544950 (532K) (unauthoritative)100%[==================================================================================================================================================================>] 544,950      172KB/s   in 3.1s   2013-08-12 22:38:16 (172 KB/s) - ‘mpc-0.8.1.tar.gz’ saved [544950]

Try to compile GCC again, and configure will produce makefile successfully. Now you can make install.

sh-3.2# pwd/Users/gerryyang/code/public/gcc-4.8.1sh-3.2# ./configure --prefix=/usr/local/gcc-4.8.1/ --enable-threads=posix --disable-checkingchecking build system type... x86_64-apple-darwin12.4.0checking host system type... x86_64-apple-darwin12.4.0checking target system type... x86_64-apple-darwin12.4.0checking for a BSD-compatible install... /usr/bin/install -cchecking whether ln works... yeschecking whether ln -s works... yeschecking for a sed that does not truncate output... /usr/bin/sedchecking for gawk... nochecking for mawk... nochecking for nawk... nochecking for awk... awkchecking for libatomic support... yeschecking for libitm support... yeschecking for libsanitizer support... yeschecking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables... checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking for g++... g++checking whether we are using the GNU C++ compiler... yeschecking whether g++ accepts -g... yeschecking whether g++ accepts -static-libstdc++ -static-libgcc... nochecking for gnatbind... nochecking for gnatmake... nochecking whether compiler driver understands Ada... nochecking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2checking for objdir... .libschecking for version 0.10 of ISL... nochecking for version 0.11 of ISL... noThe following languages will be built: c,c++,fortran,java,objc*** This configuration is not supported in the following subdirectories:     target-libmudflap target-libgo gnattools target-libada target-libbacktrace    (Any other directories should still work fine.)rm: conftest.dSYM: is a directorychecking for default BUILD_CONFIG... bootstrap-debugchecking for bison... bison -ychecking for bison... bisonchecking for gm4... gm4checking for flex... flexchecking for flex... flexchecking for makeinfo... makeinfochecking for expect... expectchecking for runtest... nochecking for ar... archecking for as... aschecking for dlltool... nochecking for ld... (cached) /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/ldchecking for lipo... lipochecking for nm... nmchecking for ranlib... ranlibchecking for strip... stripchecking for windres... nochecking for windmc... nochecking for objcopy... nochecking for objdump... nochecking for readelf... nochecking for cc... ccchecking for c++... c++checking for gcc... gccchecking for gcj... nochecking for gfortran... nochecking for gccgo... nochecking for ar... nochecking for ar... archecking for as... nochecking for as... aschecking for dlltool... nochecking for dlltool... nochecking for ld... nochecking for ld... ldchecking for lipo... nochecking for lipo... lipochecking for nm... nochecking for nm... nmchecking for objdump... nochecking for objdump... nochecking for ranlib... nochecking for ranlib... ranlibchecking for readelf... nochecking for readelf... nochecking for strip... nochecking for strip... stripchecking for windres... nochecking for windres... nochecking for windmc... nochecking for windmc... nochecking where to find the target ar... host toolchecking where to find the target as... host toolchecking where to find the target cc... just compiledchecking where to find the target c++... just compiledchecking where to find the target c++ for libstdc++... just compiledchecking where to find the target dlltool... host toolchecking where to find the target gcc... just compiledchecking where to find the target gcj... just compiledchecking where to find the target gfortran... just compiledchecking where to find the target gccgo... host toolchecking where to find the target ld... host toolchecking where to find the target lipo... host toolchecking where to find the target nm... host toolchecking where to find the target objdump... host toolchecking where to find the target ranlib... host toolchecking where to find the target readelf... host toolchecking where to find the target strip... host toolchecking where to find the target windres... host toolchecking where to find the target windmc... host toolchecking whether to enable maintainer-specific portions of Makefiles... noconfigure: creating ./config.statusconfig.status: creating Makefile

Note: At the beginning, do not pay attention, in the source file directory (gcc-4.8.1/) after configure and then make; make install will have an asserted error during the compilation, I found the cause of the error on the Internet and found no specific solution. You can use another method to avoid the above asserted error by referring to [2:

See
Installing GCC: configuration for the full documentation. A major benefit of RunningSrcdir/ConfigureFrom outside the source directory (instead of running./Configure) Is that the source directory
Will not be modified in any way, so if your build fails or you want to re-configure and build again, you simply delete everything inObjdirAnd start again.

For example, login ing and building GCC 4.6.2 shocould be as simple:

tar xzf gcc-4.6.2.tar.gzcd gcc-4.6.2./contrib/download_prerequisitescd ..mkdir objdircd objdir$PWD/../gcc-4.6.2/configure --prefix=$HOME/gcc-4.6.2 makemake install

If your build fails and your configure command has lots of complicated options you shocould try removing options and keep it simple. Do not add lots of configure options you don't
Understand, they might be the reason your build fails.

OK. The above method is used to solve the compilation problem. The compilation takes more than 1 hour. The following is the GCC version information after the compilation is successful:

4. Reference

[1] http://stackoverflow.com/questions/9450394/how-to-install-gcc-from-scratch-with-gmp-mpfr-mpc-elf-without-shared-librari (speak clearly)

[2] http://gcc.gnu.org/wiki/InstallingGCC (found bright Avenue)

[3] http://crosstown.coolestguyplanettech.com/os-x/32-install-and-configure-wget-on-os-x-lion-107 (compiling wget encountered pitfalls, here illustrates a solution)

[4] http://thomashunter.name/blog/install-wget-on-os-x-lion/ (build wget pitfalls)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.