Go: Install or upgrade GCC4.8 under Linux to support the C++11 standard

Source: Internet
Author: User

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.

    1. Get gcc 4.8.2 package: wget http://gcc.skazkaforyou.com/releases/gcc-4.8.2/gcc-4.8.2.tar.gz;
    2. Decompression: TAR-XF gcc-4.8.2.tar.gz;
    3. 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.
    4. Set up the output directory and go to the directory: mkdir GCC-BUILD-4.8.2;CD gcc-build-4.8.2;
    5. .. /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;
    6. Compile: Make; note this step and the previous step, more time-consuming;
    7. Installation: make install;
    8. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.