Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling compiler extensions Xcode

Tags:

c++

xcode

macos

How can I disable compiler extensions using C++ in Xcode? I have already try to find it in the Scheme section. But didn't find it there.

like image 598
Shourov Avatar asked Sep 01 '26 16:09

Shourov


2 Answers

https://www.learncpp.com/cpp-tutorial/configuring-your-compiler-compiler-extensions/comment-page-1/#comment-446983

For those asking about Xcode, here is how you add compiler flags:

  1. In Xcode, press CMD+1 to show the Project Navigator.
  2. In the Project Navigator click on your project, the one with the blue file icon.
  3. In the main editor window, select the Target.
  4. Click on Build Settings.
  5. Make sure "All" and "Combined" are selected.
  6. Type "c++ flag" in the search filter.
  7. You should now see the setting "Other C++ Flags" under the header "Custom Compiler Flags".
  8. Double-click to the right of that line. A small box pops up.
  9. Click the "+" button, type in "-std=c++17" and press Enter to save.
  10. Click "+" again, type in "-pedantic-errors" and hit Enter.

You're done! Click out to dismiss the popup and you'll see both flags have been added to the "Other C++ Flags" setting. You could also have single-clicked on the right and instead of the popup it turns into an editable text field. You can add flags this way too just by typing them all in one space-separated line. Just leave a space after $(OTHER_CFLAGS) and add your flags at the end. Don't remove $(OTHER_CFLAGS)!

Note 1: In Xcode 11.3 Build Settings, under the Warning Policies header you'll see settings for "Pedantic Warnings" and "Treat Warnings as Errors". Setting these both to "Yes" however, only seems to add the "-pedantic" flag. Not "-pedantic-errors" as we want. Not sure if bug or intended so for now I guess leave these both at "No" and use the Custom Compiler Flags setting as shown above.

Note 2: There is a Build Setting called "C++ Language Dialect". Just type in "dialect" in the search filter and you'll find it. You can click the drop-down and select C++17 here. This will send the flag "-std=c++1z" to the compiler so you don't have to manually add it to the custom flags setting.

Edit: Found out C++1z was the name of the draft version of C++17 before it was approved.

like image 60
Michael Rock Avatar answered Sep 03 '26 07:09

Michael Rock


1.Select the project under which your target/executable belongs.

2.Select the target for which you want to provide the compiler flags.

3.Select "Build Phases" -> "compile sources"

4.Double click against the file which generates executable file.

5.Paste the compiler flag e.g. -fno-elide-constructors

That is it. Rebuild you target and you should not see any copy constructors getting ommitted.

like image 20
Shivani Bajaj Avatar answered Sep 03 '26 06:09

Shivani Bajaj