Error building Cocos2d-x v3.9 using cmake

Hey,

I have downloaded Cocos2d-x from Github (Both v3 [Latest Commit: d0c3275281d03ae319d076a30972ac5fd7512531] and v3.9 branches [Latest Commit: 7e72a7110c46721115af8b088b082b9ad6f8fd2c]) and I’m having issues compiling it with cmake.

I’m using a MacOSX El Captain 11.10.2.

I think I am doing everything right, I have downloaded dependencies using download-deps.py, instaled Android SDK/NDK, ran setup.py to config my local vars, ran “git submodule update --init” and cmake -G “Unix Makefiles” on the root directory of cocos2d-x.

After setting up cmake and running make, it gets stuck at 42% with this error message:

34 warnings and 4 errors generated.
make[2]: *** [cocos/CMakeFiles/cocos2d.dir/ui/UIEditBox/UIEditBoxImpl-mac.mm.o] Error 1
make[1]: *** [cocos/CMakeFiles/cocos2d.dir/all] Error 2
make: *** [all] Error 2

The errors are:

In file included from /Users/username/cocos2d-x/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm:26:
/Users/username/cocos2d-x/cocos/ui/UIEditBox/UIEditBoxImpl-mac.h:92:5: error:
      unknown type name 'NSFont'
    NSFont*    constructFont(const char* fontName, int fontSize);
    ^

In file included from /Users/username/cocos2d-x/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm:26:
/Users/username/cocos2d-x/cocos/ui/UIEditBox/UIEditBoxImpl-mac.h:90:5: error:
      unknown type name 'NSPoint'; did you mean 'Point'?
    NSPoint    convertDesignCoordToScreenCoord(const Vec2& designCoord, ...
    ^~~~~~~
    Point

In file included from /Users/username/cocos2d-x/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm:30:
/Users/username/cocos2d-x/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm:568:27: error:
      no viable conversion from 'Point' (aka 'cocos2d::Vec2') to 'NSPoint'
      (aka 'CGPoint')
  ...setPosition:convertDesignCoordToScreenCoord(designCoord, _inRetinaMode)];
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/username/cocos2d-x/cocos/ui/UIEditBox/UIEditBoxImpl-mac.mm:530:25: error:
      return type of out-of-line definition of
      'cocos2d::ui::EditBoxImplMac::convertDesignCoordToScreenCoord' differs
      from that in the declaration
NSPoint EditBoxImplMac::convertDesignCoordToScreenCoord(const Vec2& desi...
~~~~~~~

The funny thing is that I can run gen-libs on cocos2d-console and it works without a hitch, but with cmake it just hangs there.

Any tips?

Thanks.

You create new project or try build test project? For what platform you’re building? I recommend reading this guide

Thanks for the reply, I think I got it now, I don’t need to run cmake to create/run projects, just the cocos cli.

I’m still a bit confused about why the cmake stuff is in the project folder, I thought that as any software that uses it, I needed to build (Using make) cocos2d-x source before I could do anything with it.

What is it actually used for? am I missing something?

Edit: I’m creating a new project from scratch and it will run on iOS. The test projects included in the source are working fine.

You don’t need precompile cocos2d-x lib. When you create new project with cocos new command, everything you need will be copied. Then you can build project by cocos compile command, or from IDE.
If you want to see examples how to use cocos2d-x components, you can run test, example for mac (“Build and Run” section)

1 Like

Thanks, I got it now.

My sample project is building without problems.