• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calling an Objective-C function from C++?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling an Objective-C function from C++?


  • Subject: Re: Calling an Objective-C function from C++?
  • From: David Duncan <email@hidden>
  • Date: Tue, 31 Jan 2012 12:34:56 -0800

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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >Calling an Objective-C function from C++? (From: Howard Moon <email@hidden>)

  • Prev by Date: Re: NSDateFormatter not working on iOS 5.
  • Next by Date: Re: Calling an Objective-C function from C++?
  • Previous by thread: Calling an Objective-C function from C++?
  • Next by thread: Re: Calling an Objective-C function from C++?
  • Index(es):
    • Date
    • Thread