Compiling with C++17 on Mac OSX using Terminal

Hello,

I always use my terminal app to compile my C++ programs. I use a Makefile, so I find it quick. As editor, I use Atom.

However, I can't compile using C++17.

My Xcode has the C++17 and it is working, I tested it. But if I try to compile using:
 
clang++ -std=c++17 test_initialization.cpp -o test_initialization

I get the following error:
 
error: invalid value 'c++17' in '-std=c++17'


It works fine if I use "-std=c++14" but, of course, I get error using this because my code have new things available for C++17, such as:
 
auto message_3{"hello3"s};


I tested the same code in my Xcode IDE and everything was ok.

My Makefile is:
1
2
3
4
5
6
7
8
9
CXX = clang++
CXXFLAGS = -std=c++14

all: $(TARGET)
  $(TARGET): $(TARGET).cpp
  $(CXX) $(CXXFLAGS) -o $(TARGET) $(TARGET).cpp

clean:
  $(RM) $(TARGET)


My Clang++ version is:
1
2
3
clang++ --version
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0


So any idea how to use C++17 on my Mac OSX terminal without the need to download or install a third party compiler not included in XCode?

Thanks! :)
I could be wrong but it seems that the 9.0 in your version is actually referring to the version of Xcode. Apparently Xcode 9.0 comes with Clang++ 4.x

See: https://stackoverflow.com/questions/46318742/apple-llvm-9-0-can-not-use-flag-c17

Try to see if -std=c++1z works for your needs. Otherwise, you might have to update your version of clang++.
@Ganado,

Thank you for the link.

I tried the "-std=c++1z" and it gave me the same error as the "-std=c++14". It doesn't compile:
 
auto message_3{"hello3"s};


What is funny is that if I use XCode IDE, I can compile my code with no errors and I have the options to chose between "-std=c++17" and "-std=gnu++17".

However, I can't use these options in my terminal app. Must be something that XCode blocks... :(


Does XCode have a way to see exactly what the command given to the compiler is? Other IDEs usually do. That would probably clear up some confusion.
@Ganado,

I finally know how to see the command generated by Xcode. I will leave the steps here.

The current Xcode 9.2 is using -std=c++1z. Even though it has the options to use -std=c++17, it is still compiling using c++1z.

In order to see the exact command, you need to use the "Report Navigator".
In the "Report Navigator" you must click on a build process on the left and enable "All Messages".
After that you will see a line for each file Xcode is compiling.
To see the details, you must click on the lines icon on the right of the list entry.
Doing that, Xcode will open up the exact build command used.

I will need to wait for Xcode 9.3 in order to use the "-std=c++17" in Terminal. It seams the Xcode 9.3 beta already has it.
Topic archived. No new replies allowed.