Linux how to configure the C++11 compilation environment
- 2020-11-25 07:26:06
- OfStack
Configuration yum source
Here we use the yum source for 163, configured as follows
Backup/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 repo file, put/etc/yum repos. d/please prepare accordingly before operation (backup), the following link for download
https://mirrors.163.com/.help/CentOS6-Base-163.repo
Run the following command to generate the yum cache
yum clean all
yum makecache
Use yum to configure the c++ compile environment
Once yum is configured, configure c++ build environment commands as follows
yum -y install gcc gcc-g++
The c++ environment is ready to be configured once the installation is complete.
Write an hello worl code as follows
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello World!"<<endl;
return 0;
}
Save the file named aa.cpp with c++ and do the following
g++ -o hello aa.cpp
./aa.cpp
Source code compilation installation c++11 compilation environment
Because yum comes with a low version of gcc, and c++11 requires es60EN4.8 or above, you need to download gcc4.8 or above to support c++11
View the local VERSION of gcc
gcc -v
This version is
gcc version 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
Get 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
The file has 100M, the download speed of foreign websites is very slow, please wait patiently (foreign vps can be downloaded and transferred)
When the download is complete, place it under /usr/local/src
unzip
tar -zxvf gcc-4.8.2.tar.gz
Compile the source and install it
Go to the gcc directory
cd gcc-4.8.2
Download the configuration to install the dependent libraries for ES99en4.8.2
./contrib/download_prerequisites
Create a compile output directory
Execute under the current path
yum clean all
yum makecache
0
Start configure
yum clean all
yum makecache
1
--enable-languages
Indicates that you want your gcc to support those languages
--disable-multilib
Do not generate cross-compilers that are compiled into executable code for other platforms
--disable-checking
The generated compiler does no extra checking during compilation
compile
Compile the output directory gcc-build-4.8.2 directly make
yum clean all
yum makecache
2
The source make process takes a long time, usually more than half an hour.
The installation
make install
Verify that the upgrade was successful
use
which gcc
Check the gcc installation up to use
gcc -v
Check the version. If it hasn't changed, close the current session and reconnect to see if it has changed to 4.8.2. If it hasn't changed, you need to restart the system
Verify that the C++11 program is available
The lambda expression is a new feature of C++11. The following procedure verifies that c++11 is available
Reference: http: / / en. cppreference. com w/cpp/container/array
yum clean all
yum makecache
4
Validation method
yum clean all
yum makecache
5
If g++ is used, it is not added
-std=c++11
Parameter, an error will be reported, as follows
yum clean all
yum makecache
6
Update the gcc dynamic link library
Source compile after upgrade install gcc compiler or run other programs, can appear sometimes similar/usr lib64 / libstdc + +. so. 6: versionGLIBCXX_3. 4.18 'not found problem. This is because when upgrading gcc, the dynamic library generated did not replace the dynamic library of the old version of gcc. It can be solved by replacing the dynamic library of the old version of gcc with the dynamic library of the latest version of gcc. Please refer to the following links
http://itbilu.com/linux/management/NymXRUieg.html