Search code examples
c++classconstructorderived-class

how to define -std=c++11 as default in g++


I'm using some features in my C++ programs that I need -std=c++11 option set in g++

Is it possible set this option as a default and don't be necessary use this all time I compile it?

Or how to set this in Makefile.


Solution

  • Yes, you typically set this in a Makefile:

    CXXFLAGS=-std=c++11 
    

    One layer above you can also detect a suitable compiler via autoconf, cmake or whichever other meta-buildtool you might deploy.

    You of course play games as define g++11 as g++ -std=c++11 but such set-ups are not portable.

    g++-6.* will default to c++14 so at some this switch will be implicit. But it might take a really long time for all those RHEL and CentOS boxen with g++-4.4.* to disappear. Those may not even handle your current project...