Compiler in MAC

I have the latest xcode version installed in xcode and terminal. I also have the lastest homebrew gcc installed in terminal.
In Xcode itself my cpp files compile fine with the latest version of c++17 but in my terminal (no matter what I do) it does not even compile features of c++11 such as int number{} for instance.
I have to manually input:
g++ -std=c++17 example.cpp
to run the latest version.
Please help. if you solve my issue Coffees are on me when you are in the bay area.
I have to manually input:
g++ -std=c++17 example.cpp

What is your "not manual" method for compiling?

Open the manual
man g++

and seek -std= from it.
What is the default in your gcc?
What options does your gcc have?
Last edited on
Xcode uses Clang as the default compiler.

Both GCC and Clang support the same -std=.... notation to specify the version of C++ being compiled.

Which version of C++ you actually get when you invoke each compiler depends on which version of the compiler you have, and whether there have been any vendor specific tweaks along the way.

No matter what the tool developers choose, their decisions are bound to annoy some subset of people.

For xcode, either the toolchain is C++17 out of the box, or the IDE is automagically adding c++17 to the compiler command line, because you ticked some box in your project settings saying "c++17".

If it really matters to you, you could set CXXFLAGS=-std=c++17 as an environment variable in your shell .bashrc (or similar).
D*mn, salem c gets the coffee....I'm all about coffee...

As @salem c points out, the point is that for a long while the defaults of the compilers have been a default to C++11 (and for a long while before, C++03), until it is specified, and Xcode is specifying that for you automatically. It is one of the benefits of an IDE.

I have to manually input:
g++ -std=c++17 example.cpp

You can put that into a Makefile. Then, in the terminal, run `make` and let it compile. Less work!
Last edited on
Registered users can post here. Sign in or register to post.