Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

c++ - how to change gcc compiler to c++11 on ubuntu

I use ubuntu 12.04 and the default gcc is 4.6.3. It is not accepting c++11 commands and is giving me output saying the command is not c++98 compatible. I checked online and have seen people advising to not change default compilers on operating system as it becomes unstable. Can anybody suggest a fix or a safe way of downloading a gcc compiler that is c++11 compliant.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As others have suggested, you need to enter the std commandline option. Let us make it easy for you

  1. Open terminal by pressing Ctrl+Alt+T
  2. sudo gedit ~/.bashrc
  3. Enter the following line as the last line

    alias g++="g++ --std=c++0x"
    
  4. Save and close the file and close the terminal.
  5. Now open terminal again and compile your c++ 11 programs simply by g++ filename.cpp

Thats it. By default it will compile for c++11 standard.

NOTE: If you follow the above mentioned option, to compile non-c++ 11 programs, you have to use

g++ --std=c++98 filename.cpp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...