Ext.: http://www.cnblogs.com/lizhenghn/p/3550996.html
The C++11 standard was unanimously adopted in August 2011, which was the first major revision of the C + + language since 1998, and improved and expanded the C + + language. Each compiler vendor then implements or partially implements the features in C + +.
To see how much support each compiler has for c++11, see the article:
This article mainly introduces how to upgrade GCC to support c++11 under Linux system. GCC is currently the most supported compiler for C++11, but requires GCC4.8 and above.
This article uses the operating system: Centos 6.4 desktop,64bit;
Original GCC version: 4.4.7;
Objective: To upgrade GCC to 4.8.2 to support c++11.
- Get gcc 4.8.2 package: wget http://gcc.skazkaforyou.com/releases/gcc-4.8.2/gcc-4.8.2.tar.gz;
- Decompression: TAR-XF gcc-4.8.2.tar.gz;
- Go to directory gcc-4.8.2, run:./contrib/download_prerequisites. This magical script file will help us to download, configure and install dependent libraries, which can save us a lot of time and effort.
- Set up the output directory and go to the directory: mkdir GCC-BUILD-4.8.2;CD gcc-build-4.8.2;
- .. /configure--enable-checking=release--enable-languages=c,c++--disable-multilib. --enable-languages says you want your GCC to support those languages,--disable-multilib does not generate a cross-compiler that compiles executable code to other platforms. The compiler generated by--disable-checking does not perform additional checks during compilation, or it can use--enable-checking=xxx to add some checks;
- Compile: Make; note this step and the previous step, more time-consuming;
- Installation: make install;
- Verification: gcc-v, or g++-V, if the GCC version shown is still the previous version, you will need to restart the system, or you can view the installation location of GCC: which GCC, and then in view version/usr/local/bin/gcc-v, usually GCC is installed at that location, if displayed as;
Indicates that the upgrade was successful.
Verify that you are working properly, as an example of a newly added std::array in c++11.
Vim Stdarray.cpp;
Enter C + + code:
1 #include <iostream> 2 #include <string> 3 #include <iterator> 4 #include <algorithm> 5 #include <array> 6 7 int main () 8 {9 //Construction uses aggregate initialization10 std::array<int, 3> A1 {{n-a}}; Double-braces required11 std::array<int, 3> a2 = {1, 2, 3};//except after =12 std::array<std::string , 2> a3 = {{std::string ("a"), "B"}};13 //container operations is SUPPORTED15 Std::sort (A1.begin (), a 1.end ()); std::reverse_copy (A2.begin (), A2.end (), std::ostream_iterator<int> (Std::cout, "")); std::cout << ' \ n '; + //ranged for loop are supported22 for (auto& s:a3) 23< C16/>std::cout << s << '; std::cout << ' \ n '; 25}
Compile: g++ -std=c++11 -o stdarray stdarray.cpp; be sure to add c++11, otherwise you may not be able to compile or run.
Run:./stdarray;
Result output:
It means that the upgraded GCC does support c++11 development.
Go: Install or upgrade GCC4.8 under Linux to support the C++11 standard