Coffee Maker
Coffee Maker

Reputation: 1573

How do I make g++ permanently compile using the C++11 standard?

I'm using g++ 4.8.1, and unless I explicitly state -std=c++11 then it always compiles C++ code using the '98 standard. How do I permanently set the flag?

EDIT: Also, I'm using Windows. And command prompt.

Upvotes: 1

Views: 602

Answers (3)

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145194

g++ is configured via a spec file.

you can google that, and edit it.

alternatives to configuring the basic compiler via its spec file include

  • batch file to invoke it

  • console alias to invoke it (use doskey command)

  • just use the Nuwen distribution, which is already configured for C++11.

Upvotes: 2

Ryan
Ryan

Reputation: 2404

You can create an alias for whichever shell you use. Usually, the alias must be stored in a start-up script for it to become permanent.

For bash:

alias g++='g++ -std=c++11'

For Window's cmd.exe:

doskey g++=g++ -std=c++11 $*

While you're at it, -Wall and -pedantic are also useful to set by default. Look them up!

Upvotes: 0

Praetorian
Praetorian

Reputation: 109079

Save the following line in a batch file, and call that instead, passing the arguments you'd normally pass to g++ to the batch file.

g++ -std=c++11 %*

This is the only reference I could find for %*

The %* modifier is a unique modifier that represents all arguments passed in a batch file.

Upvotes: 1

Related Questions