OSX native mm class compile error

Hi everyone,

I have moved my project from version 2.5 to 3.2. As soon as I add an .m or .mm file which I need for InAppPurchase and GameCenter, I can’t compile the project anymore. It looks like the #import <Cocoa/Cocoa.h> statement in the Prefix.h gets compiled and that causes errors.

‘Size’ is ambigous for example.

It worked perfectly with 2.5. Is there anything I need to do differently when trying to add native code to a 3.2 project?

Thanks.

Can you paste some code and the error messages?

A lot of class got renamed between V2 and V3 (for example CCSize became Size), which may cause problems if you have other classes with the same name (happened to me, I just had to specify the namespaces).

I get this error after adding an empty testCocoa.m and testCocoa.h file:

Lexical or Preprocessor issue
– ‘map’ file not found
---- String.h
------ bla bla … proj.ios_mac/mac/Prefix.pch:6:

I get this error when I add my empty GameCenterManager.mm/GameCenterManager.h files that implement my interface header:

Semantic issue
– Reference to ‘Size’ is ambiguous
---- MacMemory.h
------ blabla…proj.ios_mac/mac/Prefix.pch:6:

This is the content of my Prefix.pch:
###ifdef OBJC
#import <Cocoa/Cocoa.h>
###endif

The default Prefix.pch is:

#ifdef __OBJC__
    #import <Cocoa/Cocoa.h>
#endif

#ifdef __cplusplus
    #include "cocos2d.h"
#endif

Could you try this one and see if it works? Also, try to rename testCocoa.m to testCocoa.mm

I read somewhere that ‘using namespace cocos2d’ could cause problems in header files.
So I removed them all, adding coco2d:: to every occurence. Took a while but voila, I can successfully build and run my project again.

Believe it or not, this project got created with version cocos2d-x 1.0 and I migrated it 4 times now :slight_smile:

Thanks for your help!