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 upgrade GCC under Linux

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

Share

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

Today, the editor will share with you the relevant knowledge about how to upgrade GCC under Linux. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

When developing applications for Linux, C language is used in most cases, so the first problem that almost every Linux programmer faces is how to use C compiler flexibly. At present, the most commonly used C language compiler under Linux is GCC (GNU Compiler Collection), which conforms to the ANSI C standard in the GNU project. It can compile programs written in C, C++, Object C and other languages. GCC is not only very powerful, but also extremely flexible in structure.

This article describes how to upgrade the gcc compiled version by compiling the source code, because the CentOS default gcc compiled version 4.8.5 is too low to meet the requirements. So a compilation script is given here.

[root@tencent ~] # mkdir / root/gcc [root@tencent ~] # cd / root/gcc [root@tencent ~] # vim upgradeGcc.sh [root@tencent ~] # chmod + x upgradeGcc.sh

Here are the details of the script

#! / bin/bash# needs to be granted for non-root users Use the sudo command # to get the GCC source code # sudo wget https://ftp.gnu.org/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.gzwget https://ftp.gnu.org/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.gz# decompress # sudo tar-zxvf gcc-8.3.0.tar.gztar-zxvf gcc-8.3.0.tar.gz# to enter the decompressed text Folder cd gcc-8.3.0/# prerequisites for downloading and installing GCC # sudo. / contrib/download_prerequisites./contrib/download_prerequisites# return to the previous directory Set up the compilation output directory cd.. # sudo mkdir bulidmkdir bulid# to enter the output directory Execute the following command to generate the MakeFile file cd bulid/#sudo.. / gcc-8.3.0/configure-enable-checking=release-enable-languages=c,c++-disable-multilib../gcc-8.3.0/configure-enable-checking=release-enable-languages=c,c++-disable-multilib# to compile. If you want to speed up the compilation, you can add-j4 (using 4 job,-j8) after it. This value should not be set too high # sudo makemake# installation # sudo make installmake install# check version gcc-v# at this time, although the installation is finished, the path of path is still the old path, so you need to change the path environment variable cp / usr/local/lib64/libstdc++.so.6.0.25 / lib64cd / lib64rm-rf libstdc++.so.6ln-s libstdc++.so.6.0.25 libstdc++.so.6

Execute the following command and wait for the installation to complete, which is expected to take a long time.

[root@tencent ~] # chmod 777 / root/gcc/upgradeGcc.sh [root@tencent ~] #. / root/upgradeGcc.sh

Commands in shell can be executed either as a script or as a single command.

Note: during installation, there may be no C++ compilation environment. At this point, you only need to install the C++ compiler environment.

Yum install gcc-c++-y

If the class error is reported due to the lack of lib related to iconv at compile time, you need to install iconvlib, and the local which iconv can see that iconv is installed on the machine (the which iconv output is: / usr/local/bin/iconv). If you also have iconv installed on your machine, read on, otherwise install it first and then move on.

The reason for this problem is that linux ignores a series of * .so in / usr/local/lib when looking for dynamic link libraries and adds them to the configuration file.

Checking size of off_t... Configure: error: in `/ tmp/vim74/src':configure: error: cannot compute sizeof (off_t) See `config.log' for more details. Solution (with root permission)

1. Open the configuration file / etc/ld.so.conf

2. Add the following line to it

/ usr/local/lib

3. Save the file and execute the command: / sbin/ldconfig

Workaround (no root permission)

For non-root users, / etc/ld.so.conf is read-only, and there is a way to solve this problem. Execute the following command in the vim74 directory first:

Export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH / / set an additional search path for the compiler

The principle is basically similar, the root cause of modifying ld.so.conf is only to let the compiler look for dependencies under the corresponding path in the make process, here directly specify the search path, is an effect.

Next, make & & make install will be normal.

These are all the contents of the article "how to upgrade GCC under Linux". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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