Calling Objective C code within C++ using Cocoa

Started by
11 comments, last by FruitJuice27 19 years, 5 months ago
Quote:Original post by chollida1
Oh yes, I should have reminded you about the .mm extension. I always found it "hacky" that apple would compile a file based on its extension, while the whole OS does its best to sheild the user from the extention of a file.
This is standard GCC behavior but you can get around it with certain flags.

Quote:For instance i have a MessageBox.cpp that uses the windows MessageBox function if copiling for windows. I would like it to Compile for MAC using the Cocoa NSAlert.
Create a C/C++ interface for creating a message box, then create two implementation files. One will be an .mm and one will be a .cpp. You can then set up your project so that the Windows version compiles and links with the the Windows implementation and the MacOS version compiles and links with the Mac implementation. Your code calls the wrapper function. No #ifdefs necessary.
Free Mac Mini (I know, I'm a tool)
Advertisement
We use .mm. Vs.net will compile .mm file if you set up a file association for them. Just look in the registry for .cpp and copy that key for .mm.

Works well for us. igni ferroque mentioned that you can use certain compiler flags to get cpp files to work as ObjectiveC++ files but we've never had any luck getting it to work by setting the compile as ObjectiveC++ flag.

And judging by the XCode mailing list we aren't alone

Cheers
Chris
CheersChris
Thanks for the advice. Since im going to the extra trouble to write for both platforms, I might as well bite the bullet and do two files.

This topic is closed to new replies.

Advertisement