On Jan 31, 2012, at 11:31 AM, Howard Moon wrote:

>       I'd like to add the ability to support Cocoa, by adding a .mm/.h file 
> with the Cocoa code to display an NSAlert, and call it from here when the 
> preprocessor symbol MAC_COCOA is defined.  I've created the Cocoa files, but 
> how can I include and call into that code from my .cpp file?  Simply adding 
> either #import or #include of my new .h file causes many many errors, even 
> though the .mm file itself compiles fine.
> 
>       Anyone know of a very simple example showing what I need to do here?  
> All the examples I find so far show making the call from a .mm file in the 
> first place, but I can't do that because my code is also compiled for 32-bit 
> Carbon (and Windows). How do I call from a .cpp file into a .mm file?


Any file that uses Objective-C syntax must be .m/.mm or flagged to be compiled 
as Objective-C[++]. If you want to avoid Objective-C syntax in your .cpp file, 
you can either export a C[++] API to wrap the Objective-C code (the .mm's 
header would only export C[++] functionality when __OBJC__ is not defined), 
otherwise you should probably rename your .cpp file to .mm.
--
David Duncan

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to