Re: Calling an Objective-C function from C++?
Re: Calling an Objective-C function from C++?
- Subject: Re: Calling an Objective-C function from C++?
- From: Greg Parker <email@hidden>
- Date: Tue, 31 Jan 2012 13:10:39 -0800
On Jan 31, 2012, at 11:31 AM, Howard Moon <email@hidden> wrote:
> How do I call from a .cpp file into a .mm file?
Write a C or C++ function in the .mm file that is called by the .cpp file. Nothing magic.
> Simply adding either #import or #include of my new .h file causes many many errors, even though the .mm file itself compiles fine.
What are the errors? What is in your .h file? I bet your .h file is including Objective-C headers, which won't work when your .h file is included in a plain .cpp file.
> 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).
What you tried above should work, once you figure out what is wrong with your .h file.
An alternative:
1. Add Objective-C++ code to your existing .cpp file inside MAC_COCOA.
2. Tell Xcode that your .cpp file is actually Objective-C++.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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