在Linux中如何安装gcc

来源:互联网 发布:想学淘宝美工设计 编辑:程序博客网 时间:2024/06/16 20:10

第二次尝试,仍然以失败告终,所以尽量不要选择手动安装gcc,错误信息如下:

Configuration fails with ''configure: error: cannot compute suffix of object files: cannot compile''. What is the problem?

[ Permalink ]

Like any of the GNU projects, GCC is using the GNU autotools to commonly configure the compilation for the specifics of the build system. The configure script thereby uses small test programs - usually called conftest.c - to test if certain functions and/or features are available. If the compilation of such a test program fails, you'll see an error message like:

checking for suffix of object files... configure: error: in `/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc':configure: error: cannot compute suffix of object files: cannot compileSee `config.log' for more details.make[2]: *** [configure-stage1-target-libgcc] Error 1make[2]: Leaving directory `/home/manu/gcc/gcc'

This error message is quite misleading and frequently the problem has nothing to do with the message. You have to check the file 'config.log' in the directory where the error occurred. In the example above, you would have to check the 'config.log' file in the directory '/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc'. There might be several test programs that failed during the configuration, but some of these failures are non-critical. Check for the last error entry in the file.

Common causes for this error message are:

  • Required libraries for the GCC build are missing, specifically MPFR, GMP and MPC. If installed as shared libraries they must be in the runtime linker's search path so they can be found. Please, follow the instructions in the answer to Why does my ./configure and make fail?

  • The compiler crashed. For example, if there is an error such as 'conftest.c: internal compiler error:', this indicates a bug in the compiler. If you are using an unmodified version of GCC, please follow the procedure to report the bug.

经过检查发现,的确是无法打开mpc,但明明前面步骤中,已经成功安装mpc, 所以凌乱了。。。上网搜索别的解决办法,发现另外一个升级方法。

Use the mirrors listed Here and download the 4.8.1. The process is pretty straightforward. I would recommend to use this Procedure to complete your installation.

As you may know GCC doesn't support "make uninstall" and it has been suggested that you install GCC into a directory of its own and simply remove that directory when you do not need that specific version of GCC any longer. Hope this helped. Cheers

Edited: The Option 2:

I assume that you already have a former version of gcc, the easiest way could be adding PPA to your repositories and Update and upgrade you can have the latest version with no worries:

sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt-get update

this will add the new PPA to the other sources.

Then unistall the alternative:

sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++

then:

sudo apt-get install gcc-4.8sudo apt-get install g++-4.8

and as the alternative packages install :

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20sudo update-alternatives --config gccsudo update-alternatives --config g++

at the end:

sudo apt-get updatesudo apt-get upgrade -ysudo apt-get dist-upgrade

Hope this changes the --version ;)




The GNU C/C++ Compiler Collection installed by default in Linux Mint is usually not the most up to date compiler on your system. If you want to try new functions of the latest version of GCC, you need to build it. C++ programmers will be especially interested in building version 4.8.1 because:"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."


Disk space requirement: 500MB for the source and ~2.1GB for the compiled files. About 3GB space will be needed for the temporary files when compiling.

1. 

Install required packages

  • Type/Copy/Paste: sudo apt-get install binutils build-essential m4 autogen bison flex
  • Type/Copy/Paste: sudo apt-get install g++
  • You will need these packages as part of a complete build environment.
Install required packages
  • Type/Copy/Paste: sudo apt-get install binutils build-essential m4 autogen bison flex
  • Type/Copy/Paste: sudo apt-get install g++
  • You will need these packages as part of a complete build environment.

  1. 2
    Open up a terminal and type the following:
    • Type/Copy/Paste: mkdir /home/"your_user_name"/gcc_archive
    • This will create a directory to hold your downloaded packages and compiled libraries
  2. 3
    Download the following programs and place them in the gcc_archive directory
    • You will download all your packages you need to compile GCC to the /home/"your_user_name_"/gcc_archive directory. So change into the directory.
    • Type/Copy/Paste: cd /home/"your_user_name"/gcc_archive
  3. 4
    While in the /home/"your_user_name"/gcc_archive directory run the following commands.
    • Type/Copy/Paste: wget -c ftp://ftp.gmplib.org/pub/gmp-5.1.3/gmp-5.1.3.tar.bz2
    • Type/Copy/Paste: wget -c http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2
    • Type/Copy/Paste: wget -c http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz
    • Type/Copy/Paste: wget -c http://ftp.gnu.org/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.bz2
  4. 5
    Install GNU GMP Multiprecision Arithmetic Library, for arbitrary precision arithmetic:
    • Go to ftp://ftp.gmplib.org/pub/ to download the latest version, then run these commands in the folder contains that file to extract, build and install GMP:
    • Type/Copy/Paste: cd /home/"your_user_name"/gcc_archive
    • Type/Copy/Paste: sudo mkdir /opt/gmp-5.1.3
    • Type/Copy/Paste: chmod a+x gmp-5.1.3.tar.bz2
    • Type/Copy/Paste: tar -jxvf gmp-5.1.3.tar.bz2
    • Type/Copy/Paste: cd gmp-5.1.3
    • Type/Copy/Paste: ./configure --prefix=/opt/gmp-5.1.3
    • Type/Copy/Paste: make && make check && sudo make install
    • Notes: It is recommended to run make check
    • Type/Copy/Paste: cd ..
  5. 6
    Install GNU MPFR Library, Multiple-Precision Floating-Point computations with correct rounding
    • Go to http://www.mpfr.org/mpfr-current/ to download the latest version, then run these commands in the folder contains that file to extract, build and install MPFR:
    • Type/Copy/Paste: cd /home/"your_user_name"/gcc_archive
    • Type/Copy/Paste: sudo mkdir /opt/mpfr-3.1.2
    • Type/Copy/Paste: chmod a+x mpfr-3.1.2.tar.bz2
    • Type/Copy/Paste: tar -jxvf mpfr-3.1.2.tar.bz2
    • Type/Copy/Paste: cd mpfr-3.1.2
    • Type/Copy/Paste: ./configure --prefix=/opt/mpfr-3.1.2 --with-gmp=/opt/gmp-5.1.3
    • Type/Copy/Paste: make && make check && sudo make install
    • Notes: You must install GMP before installing MPFR
    • Type/Copy/Paste: cd ..
  6. 7
    Install GNU MPC Library, for arithmetic using complex numbers
    • Go to http://www.multiprecision.org/index.php?prog=mpc&page=download to download the latest version, then run these commands in the folder contains that file to extract, build and install MPFR:
    • Type/Copy/Paste: cd /home/"your_user_name"/gcc_archive
    • Type/Copy/Paste: sudo mkdir /opt/mpc-1.0.1
    • Type/Copy/Paste: chmod a+x mpc-1.0.1.tar.gz
    • Type/Copy/Paste: tar -zxvf mpc-1.0.1.tar.gz
    • Type/Copy/Paste: cd mpc-1.0.1
    • Type/Copy/Paste: ./configure --prefix=/opt/mpc-1.0.1 --with-gmp=/opt/gmp-5.1.3 --with-mpfr=/opt/mpfr-3.1.2
    • Type/Copy/Paste: make && make check && sudo make install
    • Notes: You must install GMP and MPFR before installing MPC
    • Type/Copy/Paste: cd ..
  7. 8
    Configure build options for GNU Compiler Collection (GCC)
    • Download the the latest version of GCC from http://ftp.gnu.org/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.bz2 . Since the GCC website did say that we should run configure command in another folder other than the source folder, we need to create another folder just for this (e.g. gcc481_build):
    • Type/Copy/Paste: cd /home/"your_user_name"/gcc_archive
    • Type/Copy/Paste: sudo mkdir -p /opt/gcc-4.8.1
      • This will create the directory which will hold the new GNU Compiler Collection (GCC)
    • Type/Copy/Paste: chmod a+x gcc-4.8.1.tar.bz2
    • Type/Copy/Paste: tar -jxvf gcc-4.8.1.tar.bz2
    • Type/Copy/Paste: mkdir gcc481_build
      • This will create the scratch directory to build the GNU Compiler Collection (GCC)
    • Type/Copy/Paste: cd gcc481_build
    • Type/Copy/Paste: ../gcc-4.8.1/configure --prefix=/opt/gcc-4.8.1 --with-gmp=/opt/gmp-5.1.3 --with-mpfr=/opt/mpfr-3.1.2 --with-mpc=/opt/mpc-1.0.1 --disable-multilib --enable-languages=c,c++
  8. 9
    While in the gcc481_build directory, set some environment variables to prepare for the upcoming build
    • 32-bit Linux Mint Instructions:
      • Type/Copy/Paste: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gmp-5.1.2/lib:/opt/mpfr-3.1.2/lib:/opt/mpc-1.0.1/lib
      • Type/Copy/Paste: export C_INCLUDE_PATH=/usr/include/i386-linux-gnu
      • Type/Copy/Paste: export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
      • Type/Copy/Paste: export OBJC_INCLUDE_PATH=$C_INCLUDE_PATH
      • Type/Copy/Paste: export LIBRARY_PATH=/usr/lib/i386-linux-gnu
    • 64-bit Linux Mint Instructions:
      • Type/Copy/Paste: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/gmp-5.1.2/lib:/opt/mpfr-3.1.2/lib:/opt/mpc-1.0.1/lib
      • Type/Copy/Paste: export C_INCLUDE_PATH=/usr/include/x86_64-linux-gnu
      • Type/Copy/Paste: export CPLUS_INCLUDE_PATH=$C_INCLUDE_PATH
      • Type/Copy/Paste: export OBJC_INCLUDE_PATH=$C_INCLUDE_PATH
      • Type/Copy/Paste: export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
  9. 10
    Build and install GNU Compiler Collection (GCC)
    • Type/Copy/Paste: make -j 4
    • Type/Copy/Paste: sudo make install
    • Notes: Be prepared for a long build -- it usually takes anywhere from 2 to 4 hours for a complete build, however it all depends on the speed of your processor. I would expect at least a 4 hour build/compile on most systems.
  10. 11
    Modify your system-wide environment variables to support new version ofGNU Compiler Collection (GCC)
    • Since there is no default .bashrc file for users on Linux Mint, you do not need to add the PATH to the new GCC to such a file
    • Type/Copy/Paste: sudo nano /etc/profile
  11. 12
    Then add the following lines to the end of /etc/profile, then save and close it:
    • 32-bit Linux Mint Instructions:
      • Type/Copy/Paste: export PATH=/opt/gcc-4.8.1/bin:$PATH
      • Type/Copy/Paste: export LIBRARY_PATH=/usr/lib/i386-linux-gnu
    • 64-bit Linux Mint Instructions:
      • Type/Copy/Paste: export PATH=/opt/gcc-4.8.1/bin:$PATH
      • Type/Copy/Paste: export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
  12. 13
    Use a text editor such as nano or gedit and add 3 lines to your /etc/ld.so.conf
    • Type/Copy/Paste: sudo nano /etc/ld.so.conf
    • Type/Copy/Paste: /opt/gmp-5.1.2/lib
    • Type/Copy/Paste: /opt/mpfr-3.1.2/lib
    • Type/Copy/Paste: /opt/mpc-1.0.1/lib
  13. 14
    Run the command:
    • Type/Copy/Paste: sudo ldconfig -v
      • This will reload update your /etc/ld.so.conf file
  14. 15
    Update the environment variables in your open terminal by running the following command
    • Type/Copy/Paste: . /etc/profile
  15. 16
    Verify your terminal's PATH environment variable by issuing the following command:
    • Type/Copy/Paste: printenv PATH
      • This should show /opt/gcc-4.8.1/bin is now at the front of your PATH
  16. 17
    Finally, run below commands to check the gcc version. They should output the version of GCC you have just built (e.g. 4.8.1)
    • Type/Copy/Paste: gcc --version
    • Type/Copy/Paste: g++ --version
  17. 18
    After these steps are complete without error, reboot your Linux Mint operating system and then your system will configured properly for compiling GNU C/C++ programs on your Linux Mint system.
  18. 19
    Later still, after you have confirmed that the new version is working fine you will probably want to delete the contents of /home/"your_user_name"/gcc_archive to reclaim space.
  19. 20
    Also to build a truly portable GNU GCC Compiler, one that is transferable between different GNU/Linux Mint systems see the following articleManually-Build-GNU-Compiler-Collection-from-Scratch-on-Linux-Mint-Static-Edition Good Luck and as Richard Stallman likes to say "Happy Hacking !"
  20. 21
    Location for sources:
    • ftp://ftp.gmplib.org/pub/gmp-5.1.3/gmp-5.1.3.tar.bz2
    • http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2
    • http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz
    • http://ftp.gnu.org/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.bz2
  21. 22
    Location of the GCC infrastructure:
    • ftp://gcc.gnu.org/pub/gcc/infrastructure/

Install required packages
  • Type/Copy/Paste: sudo apt-get install binutils build-essential m4 autogen bison flex
  • Type/Copy/Paste: sudo apt-get install g++
  • You will need these packages as part of a complete build environment.
0 0
原创粉丝点击