Install or upgrade GCC 4.8 under Linux to support C++11 standards

Source: Internet
Author: User
Tags include linux

The C++11 standard was unanimously adopted in August 2011, the first major revision of the C + + language since 1998, and the improvement and expansion of the C + + language. Subsequently, each compiler manufacturer implements or partially implements the features in C + +.

To see how much support the compiler has for c++11, see the article:

This article mainly describes how to upgrade GCC to support c++11 under Linux systems. For now, GCC is the most supported compiler for C++11, but it requires GCC4.8 and more versions.

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 download, configure, and install dependent libraries, which can save us a lot of time and effort.

Create the output directory and into 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 to other platform executable code. 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 that this step and the previous step, more time-consuming;

Installation: make install;

Validation: Gcc-v or g++-V, if the version of GCC that is displayed is still a previous version, you will need to reboot the system, or you can view the installation location of GCC: which GCC; and then in view version/usr/local/bin/gcc-v, where GCC is usually installed, if shown as;

Indicates that the upgrade has been successful.

Verify that it works properly, taking the new Std::array added to the c++11 as an example.

Vim Stdarray.cpp;

Enter C + + code:

#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 are supported for
    (auto& s:a3)
        std::cout << s << ";
    Std::cout << ' \ n ';    
}

Compiling: g++ -std=c++11 -o stdarray stdarray.cpp, be sure to add c++11, or you may not compile or run.

Run:./stdarray;

Result output:

Indicates that the upgraded GCC can indeed support c++11 development.

Author: cnblogs Lizhenghn

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/

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.