Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install gcc from source code compilation

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces you how to compile and install gcc from the source code, the content is very detailed, interested friends can refer to, hope to be helpful to you.

My environment: CentOS 6.2, kernel 3.1.10 x 86x64

Required configuration: Disk space > = 6GB, Mem > = 1GB

Download gcc-4.7.2.tar.bz2 from gcc.gnu.org and create the / root/buid-gcc directory, where all subsequent compilations have taken place.

Go to ftp://gcc.gnu.org/pub/gcc/infrastructure/ to download the following auxiliary installation packages: gmp-4.3.2.tar.bz2, mpfr-2.4.2.tar.bz2, mpc-0.8.1.tar.gz

Put all the above bz2 and gz ball into the / root/build-gcc directory.

1. Compile gmp-4.3.2

Expand gmp-4.3.2.tar.bz2:

# tar xf gmp-4.3.2.tar.bz2

# mkdir gmp-build

# cd gmp-build

#.. / gmp-4.3.2/configure-- prefix=/root/rpmbuild/gmp-build-- build=x86_64-linux

Note:-- the build=x86_64-linux option is very important for x86 / 64 platforms (such as the system I use), otherwise, Makefile cannot be generated.

After you generate the Makefile, compile with the following command:

# make

# make check

# make install

This installs gmp into the / root/build-gcc/gmp-build directory, the installation of gmp is complete, and the / root/build-gcc/gmp-build directory will be passed as an argument when you install other packages in the future.

two。 Compile mpfr

# tar xf mpfr-2.4.2.tar.bz2

# mkdir mpfr-build

# cd mpfr-build

#.. / mpfr-2.4.2/configure-- prefix=/root/build-gcc/mpfr-build/-- with-gmp=/root/build-gcc/gmp-build

# make

# make check

# make install

3. Compile mpc

# tar xf mpc-0.8.1.tar.gz

# mkdir mpc-build

# cd mpc-build

#.. / mpc-0.8.1/configure-- prefix=/root/build-gcc/mpc-build/-- with-gmp=/root/build-gcc/gmp-build/-- with-mpfr=/root/build-gcc/mpfr-build/

# make; make check; make install

4. Compile GCC

# tar xf gcc-4.7.2.tar.bz2

# mkdir gcc-build

Set LD_LIBRARY_PATH (optional)

# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/build-gcc/mpc-build/lib:/root/build-gcc/mpfr-build/lib:/root/build-gcc/gmp-build/lib

Create makefile

#.. / gcc-4.7.2/configure-prefix=/root/build-gcc/gcc-build/-- enable-threads=posix-- disable-checking-- disable-multilib-- enable-languages=c,c++-- with-gmp=/root/build-gcc/gmp-build/-- with-mpfr=/root/build-gcc/mpfr-build/-- with-mpc=/root/build-gcc/mpc-build/

Errors that may occur during Build:

Some packages are not installed (although "Development Tools" was previously installed with the command # yum groupinstall "Development Tools"), such as ppl and ppl-devel, there may be an error: configure: error: cannot compute suffix of object files: cannot

Compile . Check the log and find the error record:

Conftest.c:10:19: error: ppl_c.h: No such file or directory conftest.c:16: error: 'choke' undeclared (first use in this function) conftest.c:16: error: (Each undeclared identifier is reported only once conftest.c:16: error: for each function it appears in.) Conftest.c:16: error: expected'; 'before' me'

These errors can be made through the command:

# yum install ppl ppl-devel

Install these two packages to correct them.

In addition, if you are more rigorous, you should do make-k check after make, but make-k check will report that the command autogen is missing, but the problem is that it is difficult to find this autogen in CentOS, so be careless and make install directly after make.

When the make install is complete, the final executable files, such as gcc,g++, will be generated in the / root/build-gcc/gcc-build/bin directory. At this point, / root/build-gcc/gcc-build/bin does not exist in PATH. This requires putting the newly generated gcc into / usr/bin to make it "available":

# ln-s / root/build-gcc/gcc-build/bin/gcc / usr/bin/gcc-4.7

# ln-s / root/build-gcc/gcc-build/bin/g++ / usr/bin/g++-4.7

Note: the above must use an absolute path!

After that, you can program with the commands of gcc-4.7 and gallop music 4.7.

On how to compile and install gcc from the source code to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report