# Problem: Projucer adds Xcode Extra Compiler Flags to both C Flags and C++ Flags, and C++20

**URL:** <https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241>\
**Category:** MacOSX and iOS\
**Created:** [October 9, 2023, 7:36am UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241 "2023-10-09T07:36:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [October 9, 2023, 7:36am UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241/1 "2023-10-09T07:36:58Z")

</div>

This may be just an issue with the old version of Xcode I am using on my old develop machine here (10.3 on Mojave). I know I need to update this whole system.

But when I specify Extra Compiler Flags in the Projucer (7.0.7 develop) Xcode pane, they get added to both “Other C Flags” and “Other C++ Flags”.

 ![cflags](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/f/3/f38d00fb69a348addc492431253ee9041208ee8a.png)

This has not been a problem until now, when I am trying to figure out how to get Xcode 10.3 to build with c++20.

I set my C++ Language Standard to C++20 in Projucer. This generated an error in my project.

```auto
error: invalid value 'c++20' in '-std=c++20'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard
Command CompileC failed with a nonzero exit code

```

I then googled and found the advice to include `-std=c++2a -stdlib=libc++` as Other C++ Flags.

So I add them to my Projucer settings:

 ![cflags2](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/e/a/ea1eb55516b97fafabfcf729de9f9c8bb9e83870.png)

Then the error is:

```auto
error: invalid argument '-std=c++2a' not allowed with 'C'
Command CompileC failed with a nonzero exit code

```

This seems to be because those flags are added to BOTH “Other C Flags” and “Other C++ Flags”.

So if I manually remove those flags from the “Other C Flags” setting, the project builds perfectly, with c++20.

So is there anyway to tell Projucer to only add flags to “Other C++ Flags” when it rebuilds the Xcode project?

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [October 9, 2023, 11:01am UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241/2 "2023-10-09T11:01:09Z")

</div>

Hi @stephenk, although the best solution here might well be that we add some way to supply separate flags for C and C++, right now you are correct that these flags will be added to both C and C++ compilers. However I think there are some alternative solutions worth considering.

For the C++ version you should be able to set the `C++ Language Standard` to C++20 in the `Project Settings` (you can access these via the cog towards the top left of the UI). However, this is only true if you want to use this version of C++ for _all_ exporters.

For the standard library argument on Xcode libc++ is already the default argument so this can probably be omitted.

If however you do need to set this argument for any reason there is an alternative option

- Navigate to `Custom Xcode Flags` in each of the configurations of your exporter (Debug and Release in your example)
- Add `CLANG_CXX_LIBRARY=libc++` (or replace libc++ with whatever you need)

Once you’ve done the above you may find your issue is resolved, if however it’s not there is still another option for Xcode exporters.

- Navigate to `Custom Xcode Flags` in each of the configurations of your exporter (Debug and Release in your example)
- Add `OTHER_CPLUSPLUSFLAGS=$(OTHER_CPLUSPLUSFLAGS) -Wno-missing-braces -Wno-switch-enum -Wno-four-char-constants -std=c++2a -stdlib=libc` (or whatever flags you want, each separated by a single space character)

Note the first argument, `$(OTHER_CPLUSPLUSFLAGS)` ensures any flags already set (for example if you’ve enabled `Add Recommended Compiler Warning Flags`) are not overridden by this change.

To keep this to a minimum you may like to use the `Extra Compiler Flags` field for any flags that work for both C and C++ and only pass the C++ arguments via this back door method.

If all else fails and you need further customisation it may be worth considering our CMake support as this should generally give you a greater level of customisation.

I hope that helps.

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [October 9, 2023, 2:31pm UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241/3 "2023-10-09T14:31:36Z")

</div>

Thanks so much for your quick reply!

> [@anthony-nicholls](#):
>
> For the C++ version you should be able to set the `C++ Language Standard` to C++20 in the `Project Settings` (you can access these via the cog towards the top left of the UI). However, this is only true if you want to use this version of C++ for _all_ exporters.

Understood, I want to eventually do this on Windows VS 2019 as well, which is my other platform at the moment.

> [@](#):
>
> For the standard library argument on Xcode libc++ is already the default argument so this can probably be omitted.

You are correct, it’s not needed, so I’ve nixed this.

> [@](#):
>
> - Navigate to `Custom Xcode Flags` in each of the configurations of your exporter (Debug and Release in your example)
> - Add `OTHER_CPLUSPLUSFLAGS=$(OTHER_CPLUSPLUSFLAGS) -Wno-missing-braces -Wno-switch-enum -Wno-four-char-constants -std=c++2a -stdlib=libc` (or whatever flags you want, each separated by a single space character)
> 
> Note the first argument, `$(OTHER_CPLUSPLUSFLAGS)` ensures any flags already set (for example if you’ve enabled `Add Recommended Compiler Warning Flags`) are not overridden by this change.

When I use this, it seems to copy the existing “Other C Flags” to “Other C++ Flags”.

Before (using the Xcode (macOS) Extra Compiler Flags field ONLY):

 ![flags1](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/5/7/57dad9b504234f4aaf52d0c8c7c070e5480320c7.png)

 ![flags2](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/c/e/cef23b763bc76c368ac14a899061704b7dd9e5d8.png)

After, removing that last flag from Xcode (macOS), and putting it in Xcode Debug (only, for now):

 ![flags3](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/5/1/518559249a68d594c38ccac80a46267afa4cf6c7.png)

 ![flags4](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/3/c/3c5921daf478ba4617fc41edd18958b62cd0afb0.png)

 ![flags5](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/2/f/2fd8d765a9cc43e970e31a59e25ccffa2d14f1e6.png)

- it DOES add the extra flag at the end of the Other C++ Debug flags, but again the rest are a duplicate of the Other C flags. This seems something wrong here.

- However, it compiles and runs perfectly fine. (!)

PS. I absolutely love the cross-platform ease of using the Projucer. I’d like to stay away from CMAKE if I can. 😁

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [October 10, 2023, 10:56pm UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241/4 "2023-10-10T22:56:25Z")

</div>

@anthony-nicholls - that seems like a bug in Projucer, doesn’t it? I was hoping to hear something more from you on this before I proceed with modifying the rest of my projects. I can see you’re busy from the other threads. 😉

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [October 11, 2023, 7:03am UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241/5 "2023-10-11T07:03:29Z")

</div>

I’m not sure I’ll take a quick look today.

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [October 11, 2023, 3:35pm UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241/6 "2023-10-11T15:35:06Z")

</div>

@stephenk this seems to be an Xcode _feature?_ It seems if you use `$(OTHER_CPLUSPLUSFLAGS)` as a value to `OTHER_CPLUSPLUSFLAGS` it will include the C flags, I also found if you specify `OTHER_CFLAGS` without specifying any `OTHER_CPLUSPLUSFLAGS` it will automatically add `$(OTHER_CFLAGS)` to `OTHER_CPLUSPLUSFLAGS`.

I think generally speaking all C flags will work as C++ flags and you probably don’t want to miss any of the C flags in your C++ flags, so I guess Xcode is trying to be helpful, therefore I think this is likely intentional behaviour.

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [October 11, 2023, 3:37pm UTC](https://forum.juce.com/t/problem-projucer-adds-xcode-extra-compiler-flags-to-both-c-flags-and-c-flags-and-c-20/58241/7 "2023-10-11T15:37:57Z")

</div>

> [@anthony-nicholls](#):
>
> therefore I think this is likely intentional behaviour.

Thanks for this! Will move forwards and see what happens.
