Linux configuration C + + 11 compiling environment

Time:2021-2-6

Configure Yum source

Here we use the yum source of 163, and the configuration is as follows

Back up / etc first/ yum.repos .d/CentOS- Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

Download the corresponding version of repo file and put it into / etc/ yum.repos . D / (please make corresponding backup before operation), the following is the download link

https://mirrors.163.com/.help/CentOS6-Base-163.repo

Run the following command to generate the yum cache

yum clean all
yum makecache

Configure C + + compilation environment using yum

After configuring yum, the command to configure the C + + compilation environment is as follows

yum -y install gcc gcc-g++

After the installation, the C + + environment can be configured.

Write a hello worl code as follows

#include

using namespace std;
int main()
{
	cout<

The above code is saved in a file named aa.cpp , compile in C + + and do the following

g++ -o hello aa.cpp
./aa.cpp

Source code compilation and installation of C + + 11 compilation environment

Because the version of GCC that comes with Yum is too low, and C + + 11 needs to be supported by gcc4.8 or above, you need to download gcc4.8 or above to support c + + 11

View local GCC version

gcc -v

This version isgcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)

Get the source code of gcc4.8.2

The source code is placed in the SRC directory by default

cd /usr/local/src
wget http://gcc.skazkaforyou.com/releases/gcc-4.8.2/gcc-4.8.2.tar.gz

There are 100m files, the download speed of foreign websites is very slow, please wait patiently (you can download and transfer by foreign VPS)

After downloading, put it under / usr / local / SRC

decompression

tar -zxvf gcc-4.8.2.tar.gz

Compile the source code and install it

Enter the GCC directory

cd gcc-4.8.2

Download and install the dependency Library of gcc4.8.2

./contrib/download_prerequisites

Create compile output directory

Execute in the current path

mkdir gcc-build-4.8.2

Start configure

../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
  • --enable-languagesWhich languages do you want your GCC to support
  • --disable-multilibDo not generate cross compilers that are compiled into executable code for other platforms
  • --disable-checkingThe generated compiler does not do additional checks during compilation

compile

Make directly in the compile output directory gcc-build-4.8.2

make

The source code make process takes a long time, generally takes more than half an hour.

install

make install

Verify that the upgrade is successful

usewhich gccCheck the installation of GCC, usegcc -vCheck the version. If it has not changed, please close the current session and reconnect to see if it has changed to 4.8.2. If it has not changed, you need to restart the system

Verify the availability of C + + 11 program

Lambda expression is a new feature of C + + 11. The following program can verify whether C + + 11 is available

reference resources: http://en.cppreference.com/w/cpp/container/array

#include 

using namespace std;

int main()

{

   int n = [] (int x, int y) { return x + y; }(5, 4);

   cout << n << endl;

}

Verification method

g++ -std=c++11 -o lambda vv.cpp

If you use G + + without adding-std=c++11Parameter, an error will be reported as follows

[[email protected] tmp]# g++ -o lambda vv.cpp 
vv.cpp: In function ‘int main()’:
vv.cpp:9:46: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
    int n = [] (int x, int y) { return x + y; }(5, 4);
                                              ^

Update GCC DLL

After installing GCC in source code compilation and upgrading, when compiling programs or running other programs, sometimes it will appear something like / usr / lib64 / libstdc + +. So. 6: version glibcxx_ 3.4.18 ‘not found. This is because when upgrading GCC, the dynamic library generated does not replace the dynamic library of the old version of GCC, so it can be solved by replacing the dynamic library of the latest version of GCC with the dynamic library of the old version in the system. Please refer to the following links

http://itbilu.com/linux/management/NymXRUieg.html


Remember to praise me!

We have carefully arranged video courses and e-books from entry-level, advanced and practical in all directions of computer. We can always find the learning materials you need according to the reasonable classification of the catalogue. What are you waiting for? Pay attention to download it!!!

resource-introduce

If you don’t forget, there will be an echo. Please give me a compliment. Thank you very much.

I am a bright brother in the workplace, YY Senior Software Engineer, with four years of working experience. I refuse to be a leading slash programmer.

Listen to me, more progress, a shuttle of procedural life

If you are lucky enough to help you, please give me a “like” to pay attention to it. If you can comment on it and give me encouragement, I will be very grateful.

List of articles of workplace bright brother:More articles

wechat-platform-guide-attention

All my articles and answers have cooperation with the copyright protection platform. The copyright belongs to brother Liang in the workplace. Without authorization, reprint must be investigated!

Recommended Today

Use of Android WebView (super detailed usage)

1.1 overview of WebView Android WebView is a special view on the Android platform. It can be used to display web pages. This WebView class can be used to display only one online web page in the app. Of course, it can also be used to develop browsers. The internal implementation of WebView uses WebKit […]