Reputation: 844
How do I enable C++17 in Xcode (9.4.1) on OSX High Sierra (10.13.5)?
Upvotes: 26
Views: 25271
Reputation: 4528
When using development CocoaPods (writing a C++ library) I had also to update podspec
of this library containing c++ 17 code to make compile host application which included this pod.
So I added these flags to library's podspec
spec.xcconfig = {
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"CLANG_CXX_LIBRARY" => "libc++"
}
Upvotes: 5
Reputation: 844
Steps to use C++17 in Xcode (9.4.1) on OSX High Sierra (10.13.5):
Verification steps:
Now when I output __cplusplus, I see 201703, and I am able to compile C++17 features, such as if constexpr.
template<class T>
int compute(T x) {
if constexpr( supportsAPI(T{}) ) {
// only gets compiled if the condition is true
return x.Method();
} else {
return 0;
}
}
int main(){
cout << __cplusplus << endl;
return 0;
}
Output:
201703
Program ended with exit code: 0
Upvotes: 34