Pages

getteammates.com

Thursday, 7 May 2015

Compiling C++11 and C++14 programs with GCC

Compiling C++11 programs

With gcc 4.7 and above we can use -std=c++11 or -std=c++0x or -std=gnu++0x or -std=gnu++11 option to compile the programs as shown below,
g++ -std=c++11 hellocpp11.cpp

For earlier version of GCC, try -std=c++0x or -std=gnu++0x
g++ -std=c++0x hellocpp11.cpp

Please see the link https://gcc.gnu.org/projects/cxx0x.html for more information on feature support.

Compiling C++14 programs

C++14 is supported from gcc 4.9 onwards, so please update your gcc if it is below 4.9.
g++ -std=c++14 hellocpp14.cpp

If the default g++ compiler is not of version 4.9 and you have updated it, please use the compiler with version suffix. For example,
g++-4.9 -std=c++14 hellocpp14.cpp

-std=c++1y or -std=gnu++1y or or -std=gnu++14 can also be used instead of -std=c++14

Please see the link https://gcc.gnu.org/projects/cxx1y.html for more information on feature support.

Updating GCC to version 4.9 in Ubuntu

We will use toolchain ppa test repository to update the GCC version. Use below given commands to complete the installation.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9

After finishing the installation you can use g++-4.9 to compile programs written in c++14.

Proxy configuration

In case you are under proxy, try setting the following environment variables.
export http_proxy=http://<host>:<port>
export https_proxy=http://<host>:<port>

Also try add-apt-repository with sudo -E option if just sudo did not work for you.

In case your proxy server requires user name and password, try setting the proxy environment variables with user name and password
export https_proxy=<user_name>:<password>@<host>:<port>

No comments:

Post a Comment