# "Reference to 'Component' is ambiguous" - Obj-C and C++

**URL:** <https://forum.juce.com/t/reference-to-component-is-ambiguous-obj-c-and-c/13766>\
**Category:** General JUCE discussion\
**Created:** [October 23, 2014, 7:36pm UTC](https://forum.juce.com/t/reference-to-component-is-ambiguous-obj-c-and-c/13766 "2014-10-23T19:36:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)\
**Post date:** [October 23, 2014, 7:36pm UTC](https://forum.juce.com/t/reference-to-component-is-ambiguous-obj-c-and-c/13766/1 "2014-10-23T19:36:36Z")

</div>

I'm trying to build a project with a .mm file which houses some Objective-C code mixed with Juce C++.

I'm getting lots of errors like "Reference to 'Component' is ambiguous". These all seem to be coming from dRowAudio library files.&nbsp;

This is the first time I'm trying to build since introducing Objective-C into the project. Can anyone direct me to where the conflict might be coming from?

EDIT: Not sure if this is to do with dRowAudio or not.. if I remove the .mm file from the project I get lots of Objective-C related errors like:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:373:19: Unknown type name 'NSString'; did you mean 'String'?

Any clues?&nbsp;

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [October 23, 2014, 9:40pm UTC](https://forum.juce.com/t/reference-to-component-is-ambiguous-obj-c-and-c/13766/2 "2014-10-23T21:40:08Z")

</div>

I don't think this is due to any of my code, it's always used Obj-C internally. I think you must be including your Obj-C code incorrectly.

Take a look at how I include the iOS code in the module or how Jules includes the native stuff on OSX/iOS. Essentially, you can't include any Obj-C code in your main app. When declaring classes that use Obj-C, use void\* pointers in-place of any Obj-C classes, you can always static cast them on the definition side (in the mm file).

Make sure you include any Obj-C headers first, before any JUCE code and outside of any namespaces.

If you follow these rules you should be ok.

---

<div class="post-metadata">

**Author:** ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)\
**Post date:** [October 24, 2014, 5:14pm UTC](https://forum.juce.com/t/reference-to-component-is-ambiguous-obj-c-and-c/13766/3 "2014-10-24T17:14:35Z")

</div>

thanks Dave&nbsp;

I've been trying to wrap my head around this post to help my understanding:&nbsp;http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++

I've been looking through Juce and dRowAudio classes that use Objective-C, and things are beginning to make sense.

In your iOS related classes I see them starting with:

```
#if JUCE_IOS

} // namespace drow
```

which seems strange as its starting with a closing curly brace. Can you explain whats going on there?&nbsp;

Also, apologies if I was making it sound like there were issues withe the dRowAudio code, I quickly realised it was due to the way I'm using Objective-C in my .mm file.&nbsp;

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [October 24, 2014, 5:23pm UTC](https://forum.juce.com/t/reference-to-component-is-ambiguous-obj-c-and-c/13766/4 "2014-10-24T17:23:48Z")

</div>

Objc-C has no concept of namespaces so you need to jump out of any before including Obc-C code.

As I'm inside the drow namespace at that point in the file I add the closing brace (we're now at global scope), write any Obj-C code and then re-enter the drow namespace before the C++ code.

This ensures the C++ class interface is in the correct namespace whilst the inner Obc-C class is outside it.

It's a real pain to get all this to work properly but hopefully once you see what's going on it should make sense (took me a few goes). Good luck!

---

<div class="post-metadata">

**Author:** ![adamwilson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamwilson/32/1387_2.png) [@adamwilson](https://forum.juce.com/u/adamwilson)\
**Post date:** [October 25, 2014, 11:49pm UTC](https://forum.juce.com/t/reference-to-component-is-ambiguous-obj-c-and-c/13766/5 "2014-10-25T23:49:07Z")

</div>

Thanks, I'm definitely a lot closer - followed the pattern of the dRowAudio native modules.&nbsp;

However I'm stuck on compile time errors "Undefined symbols for architecture ..." for all the methods defined in my .mm file.

I've tried various combinations of include/import etc and searched the web, I think its to do with it not finding or including the .mm file, however I can't include it directly as then you get a barrage of Obj-C related errors...&nbsp;

any pointers greatly appreciated.&nbsp;

Thanks&nbsp;
