1.下载
镜像站点:https://gcc.gnu.org/mirrors.html
速度还不错的:ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/
2.解压安装依赖库
./contrib/download_prerequisites
3.配置
./configure --disable-multilib(不生成编译为其他平台可执行代码的交叉编译器)
4.编译安装
make && make install
5.测试代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include
<iostream> #include
<string> #include
<iterator> #include
<algorithm> #include
<array> int
main() { //
construction uses aggregate initialization std::array<int,
3> a1{ {1,2,3} }; //
double-braces required std::array<int,
3> a2 = {1, 2, 3}; //
except after = std::array<std::string,
2> a3 = { {std::string( "a" ), "b" }
}; //
container operations are supported std::sort(a1.begin(),
a1.end()); std::reverse_copy(a2.begin(),
a2.end(), std::ostream_iterator<int>(std::cout, "
" )); std::cout
<< '\n' ; //
ranged for loop is supported for (auto&
s: a3) std::cout
<< s << '
' ; std::cout
<< '\n' ; } |
如果出现如下报错:
/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./test)
更新软连接即可:
/usr/lib64/libstdc++.so.6 -> /usr/lib64/libstdc++.so.6.0.21