How to install gcc in Ubuntu

Source: Internet
Author: User
Tags gmp
In order to install the miserable GCC under Ubuntu, the younger brother racked his brains for three days... When I figure out the dependency between the broken software m4, gmpmpfr, and NMPC, follow the strong Duniang's instructions, once installed, it does not work! Shit! When I had to give up the idea of GCC, it was Du Niang! In order to install the miserable GCC under Ubuntu, the younger brother racked his brains for three days... When I figure out the dependency between the broken software m4, gmpmpfr, and NMPC, follow the strong Duniang's instructions, once installed, it does not work! Shit! When I had to give up the idea of GCC, it was Du Niang! 650) this. width = 650; "src =" http://upload.server110.com/image/20131001/0056391a7-0.gif "/> The original Ubuntu11.04 built-in GCC !!! We recommend that you check whether your Linux system has GCC before installing GCC.
650) this. width = 650; "src =" http://upload.server110.com/image/20131001/0056395006-1.jpg "/>
The following is how I learned how to install GCC on Ubuntu in this miserable three days:
Installation process
Step 1: Download the gcc-4.6.0.tar.bz2 file from the website http://gcc.gnu.org
Step 2: drag the file to the tmp directory. Then extract, in the command line tar vxjf gcc-4.1.1.tar.bz2,
After decompression, you can see that there is a gcc-4.6.0 file under the tmp Directory
650) this. width = 650; "src =" http://upload.server110.com/image/20131001/0056392F0-2.jpg "/>
Step 3: configure the source file with the command
Mkdir gcc-build
Cd gcc-build
../Gcc-4.6.0/configure -- prefix =/usr/local/gcc-4.6.0 -- enable-threads = posix -- disable-checking -- disable-multilib -- enable-classes ages = c, c ++
Compilation error reminder:
650) this. width = 650; "src =" http://upload.server110.com/image/20131001/0056392432-3.png "/>
Reminder: configure: error: Building GCC requires GMP 4.2 +, MPFR2.3.1 + and MCM 0.8.0 +.
It indicates that the gcc installation requires three libraries: GMP, MPFR, and NMPC, and three packages are downloaded from the Internet. Since MPFR depends on GMP, while nmms depends on GMP and MPFR, it is necessary to install GMP first, followed by MPFR, and finally the nmms. The three libraries I use are gmp5.0.1, mpfr2.4.2, and mpc0.8.1.
Install GMP first. Decompress the GMP compressed package, get the source code directory gmp-5.0.1. Create a temporary compilation directory under the Directory of the same level. name it gmp-build. Then, configure the installation options, go to the gmp-build directory, and enter the following command for configuration:
../Gmp-5.0.1/configure -- prefix =/usr/local/gmp-5.0.1
Here the -- prefix option indicates where the library is to be installed, and I install it in the/usr/local/gmp-5.0.1 directory, which will be used in subsequent installations. However, the system prompts that m4: gmp configure: error: No usable m4 in $ PATH or/usr/5bin is missing. M4 is a macro processor.
Check the solution to this problem on the Internet and run the following command to install it:
Sudo aptitude install build-essential m4
Or find m4 in the built-in software center.
650) this. width = 650; "src =" http://upload.server110.com/image/20131001/0056392647-4.jpg "/>
With the help of du Niang, I finally realized that the correct installation process is as follows:
In linux, the "installation" of software generally requires three steps:
That is, the configure, make, and makeinstall commands are compiled. any command installed has doubts or wants to view command-related parameters, you can add the "-- help" parameter after the command to view the parameters required for the installation command.
Next, it should be noted that, due to any possible situation, the configure, make, and makeinstall commands may report errors. If an error occurs, the prepare command will provide an error message, that is, the error prompt, you need to solve the problems in the installation for the error type. if there is a problem, you can search for the error information on baidu or google. you should have your answer, however, it is recommended that you search on google. Linux is open-source and there are many customers in the world. There must be people who encounter the same problems as you. Therefore, if there is any error, contact du Niang and fail. The above information is very large. You can also go to the relevant Ubuntu Forum to find, such as: http://forum.ubuntu.org.cn/index.php? Sid = c9ccb2d7adcf8fdb78ac99d75581a332 OK, continue to the topic .....
1. install GCC requires four related software:
M4 (an implementationof the traditional Unix macro processor ),
Gmp (GNU Multiple PrecisionArithmetic Library ),
Mpfr (that is, multiple-precisionfloating-point computations with correct rounding)
PC (C library for the arithmetic ofcomplex numbers with arbitrarily high precision and correctrounding)
Download 3 software packages and install reference http://www.comdyn.cn/from-web/68-server-setup/164- Centos-48-gcc0000.html
Their dependencies such as the right figure ----------- 650) this. width = 650; "src =" http://upload.server110.com/image/20131001/0056392916-5.png "/>
Install the agent in the sequence from the inner ring to the outer ring (the installation of gmp requires m4, while the installation of mpfr depends on gmp, while that of MCM depends on gmp and mpfr. Therefore, the installation of m4 and the installation of gmp must be followed, followed by mpfr, and finally the mpc)
The versions of the last three libraries I installed are
650) this. width = 650; "src =" http://upload.server110.com/image/20131001/0056393420-6.png "/>
(I) when installing m4, the system will prompt "m4: gmp configure: error: nousable m4 in $ PATH or/usr/5bin "error. Therefore, you must first install m4. the command is as follows:
Tar? Zxvf m4.tar.gz first decompress the file and then enter the m4 directory.
./Configure CC = "cc"
Make
Make install
Since the installation directory is not specified, after installation, you can view the m4 executable file under the default/usr/local/bin directory, which is a macro processor.
(II) for the installation of gmp, all subsequent installations are installed under the specified directory, so I use root superuser for operations and use su command to switch to Super User. Since I installed gmp, mpfr, and NMPC to the/usr/local/gmp432,/usr/local/mpfr242, and/usr/local/mpc082 directories respectively, therefore, you must first enter the/usr/local/directory to run
Mkdir gmp432
Mkdir mpfr242
Mkdir mpc081
After completion, go to the directory where gmp-4.3.2.tar.gz is located and start to install gmp,
Tar? Vxzf gmp-4.3.2.tar.bz2 compresses and then enters the gmp-4.3.2 Directory
Cd gmp-4.3.2 (do not know how to INSTALL can take a look at the unzip the INSTALL file under the Directory)
./Configure -- prefix =/usr/local/gmp432
Make
Make check
Make install
After installation, you can view three folders in the/usr/local/gmp432 directory.
(III) install mpfr,
Tar? Vxzf mpfr-2.4.2.tar.bz2 first decompress, then go to the mpfr-2.4.2 Directory
Cd mpfr-2.4.2
./Configure -- prefix =/usr/local/gmp432 -- with-gmp =/usr/local/gmp432
Make
Make check
Make install
Run the command (still under the superuser) to INSTALL the mpc. if you do not know how to INSTALL the command, you can check the decompressed INSTALL file,
Tar? Zxvf mpc-0.8.1.tar.gz first decompress, then enter the mpc-0.8.2 Directory
Cd mpc-0.8.1
./Configure -- prefix =/usr/local/mpc-0.8.1 -- with-gmp =/usr/local/gmp432 -- with-mpfr =/usr/local/mpfr242
Make
Make check
Make install
After these three libraries are installed, you can officially start to install gcc.
As before, under the same directory of the folder decompressed by gcc, create a temporary directory for compiling gcc: gcc-build.
Mkdir gcc-buildcd gcc-build
650) this. width = 650; "src =" http://upload.server110.com/image/20131001/00563964b-7.jpg "/>
After entering this directory, configure the installation options:
../Gcc-4.6.0/configure -- prefix =/usr/local/gcc-4.6.0 -- enable-threads = posix -- disable-checking -- disable-multilib -- enable-classes ages = c, c ++
There are many gcc configuration options. for details, refer to the installation instructions under the gcc source file directory. Only the c and c ++ compilers are installed here. Then start make compilation. I thought it would be okay, but an error occurred while compiling: errorwhile loading shared libraries: libmp C. so.2: cannot open into dobject file: No such file or directory.
After finding a solution on the Internet, you need to add the environment variable LD_LIBRARY_PATH to point out the location of the first three libraries. type the following command:
ExportLD_LIBRARY_PATH = $ LD_LIBRARY_PATH:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-2.4.2/lib
Then run
Make
Then wait patiently .........
After a long wait of two hours, the compilation was completed. In the installation instructions, there is still a test step, but it is optional and I have no patience to test it. Install makeinstall directly. now gcc is fully installed. However, the new version of gcc cannot be used yet, because the new version of executable files have not been added to the command search path. Here I have created a soft link for the new gcc and g ++ commands. Enter the/usr/bin directory and type the following command to create a soft link.
Sudo ln-s/usr/local/gcc-4.5.0/bin/gcc gcc45
Sudo ln-s/usr/local/gcc-4.5.0/bin/g ++ 45
In this way, when using the new version of gcc, I can use the gcc45 and g ++ 45 commands, as well as the original gcc Compilation program. Of course, you can also directly link the gcc and g ++ commands in the/usr/bin directory to the new version of the gcc executable file. Before using the SDK, you have to add the paths of the preceding three libraries to the environment variable LD_LIBRARY_PATH. Otherwise, an error occurs during program compilation. Because I don't want to generate environment variables every time I compile the program, I need to edit the bash. bashrc file in the/etc directory to configure the shell environment. Add the following statement to the file:
LD_LIBRARY_PATH =:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gcc-4.5.0/lib
Export LD_LIBRARY_PATH
After saving and restarting the system, you can use the newly installed gcc.
You must note that there are many gcc configuration options. for details, refer to the installation instructions in the gcc source file directory. Only the c and c ++ compilers are installed here. Then start make compilation.
Before using the SDK, you have to add the paths of the preceding three libraries to the environment variable LD_LIBRARY_PATH. Otherwise, an error occurs during program compilation. Because I don't want to generate environment variables every time I compile the program, I need to edit the bash. bashrc file in the/etc directory to configure the shell environment. Add the following statement to the file:
LD_LIBRARY_PATH =:/usr/local/mpc-0.8.1/lib:/usr/local/gmp-5.0.1/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gcc-4.5.0/lib
Export LD_LIBRARY_PATH
After saving and restarting the system, you can use the newly installed gcc.
It should be noted that if make has an error and you need to re-configure, first run makedistclean to clear the make information and then re-configure.
The command for extracting * .tar.gz is tar? Zxvf * .tar.gz
The command for extracting * .tar.bz2 is tar-jxvf * .tar.bz2.
After the installation is complete, you can use which gcc to check whether the installation is complete. after the command is run, the terminal displays the gcc installation path.
650) this. width = 650; "src =" http://upload.server110.com/image/20131001/00563a312-8.jpg "/>
After finishing the work, close the work ·······
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.