Including Carbon.h causes conflict for "Button"

Hi there,

I’m a newbie on JUCE. I’m now writing the several code for my apps.
I want to use some carbon APIs in my code, so I put #include <Carbon/Carbon.h> in my header file.
As the result, I’ve got several errors as follows.

/Users/hayashi/src/JUCETest/CMainContent.cpp:159: error: variable or field ‘buttonClicked’ declared void
/Users/hayashi/src/JUCETest/CMainContent.cpp:159: error: ‘int CMainContent::buttonClicked’ is not a static member of ‘class CMainContent’
/Users/hayashi/src/JUCETest/CMainContent.cpp:159: error: ‘Button’ was not declared in this scope
/Users/hayashi/src/JUCETest/CMainContent.cpp:159: error: ‘pButton’ was not declared in this scope
/Users/hayashi/src/JUCETest/CMainContent.cpp:160: error: expected ‘,’ or ‘;’ before ‘{’ token

There is a class “Button” in JUCE but there’s also “Button()” function in Carbon API.

Are there any workaroung for this or did I mistake/misunderstand something?

Best regards,
Masanao Hayashi
Korg Inc.

Have a look in juce.h, line 90, and try adding another line that says

If that works, let me know and I’ll add it to the build. (You’d need to make sure you include Carbon.h before juce.h for it to work, of course).

Thanks! I did it as you said, now it works. I added it into juce.h like this, #ifdef JUCE_MAC #define Component JUCE_NAMESPACE::Component #define MemoryBlock JUCE_NAMESPACE::MemoryBlock #define Point JUCE_NAMESPACE::Point #define Button JUCE_NAMESPACE::Button #endif
And the prefix file of my project is now,[code]#include <Carbon/Carbon.h>

Yeah, it works fine. Please add it in the next release if you can. :slight_smile:

Best regards,
Masanao Hayashi
Korg Inc.

Ok, will do. Thanks.

Adding #define Button JUCE_NAMESPACE::Button

seems to cause compile errors if you include juce.h first and then carbon.h

Well I’d suggest the same thing as with Windows: always include the system headers first, then the juce headers. I can make sure that always works, but can’t guarantee to make it work the other way round.