Can't run cocos2d-x on M1 Chip

Hello everyone! I just get started to cocos2d-x but I have a problem. I’m following common steps to create a “Hello World” project. But I’m taking errors even if I try it on mac directory by “cmake …/… -GXcode” command or on ios directory by “cmake …/… -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos” command.

If I try it on mac directory I take this error:

If try it on ios directory taking this error:

but when I change libz.dylib and libiconv.dylib or remove them, taking this error:

So, how can I run this? Thank you for your time :smiling_face_with_three_hearts:

Enviroment:
MacOS Big Sur
Macbook Air M1 Chip
XCode 12.5.1
Cocos2d-x 4.0
Cmake 3.21.2

We don’t support the m1 chip at this time

1 Like

So, no way to work on M1 at the moment? Even for just practice on starter level? :slightly_frowning_face:

If there is a solution I’m not familiar with it. I don’t have an M1 to even work with.

1 Like

Alright then. Thank you for your time. :pray:t5::relaxed:

Cocos2dx (I use 3.17) works just fine on an M1 (my fat binary App is live in the Mac Appstore). No need for any adjustments, just make sure to link with M1 compiled dependencies (quite easy to find those online, compile yourself or use the ones from Cocos Builder). ARM libraries for iOS are not the ones to link to.

1 Like

Yes! 3.17 is works fine on M1. Thank you so much! :heart_eyes: :upside_down_face:

Hi @pinky2012
Can you please give detailed reply? Like what libraries need to reply and in which folder?
That will be great for lot of developers.
Thanks.

For any prebuilt library your app uses, you would need to find or create a “fat” library that contains both Intel and Apple silicon versions of the library (so the the libXXX.a files). There is nothing more to it really.

Which libraries and which folders depends heavily on your project and your cocos version. Most you can find in the Cocos2d/external folder. You’d have to replace all the Mac libraries (that you use and link against) with fat libraries also containing the Apple silicon build.

In my case I just started the build process (changed target to Intel + Apple Silicon) and I fixed (i.e. created or downloaded fat libraries) each error that I got. In some cases I just removed the dependency as I am not using it.

Most external libraries Cocos2d-x uses are also used by Cocos Creator. As Cocos Creator is Apple silicon compatible, most linker errors are solved by replacing your Cocos2d external dependencies for Mac with the ones from Cocos Creator (not just the lib files, also the header files. And if you do so , make sure you don’t mess up builds for other platforms).

I got my app to work within a few hours (and that was including making a version of the Nakama library for Apple Silicon that has tons of other dependencies as well).

@pinky2012 do you mind sharing a copy of you cocos2dx for the community since you already done the migration? It will save me and others some work :slight_smile:

Thank you!

are you sure about that?

I’m sure. We haven’t done any work for the M1. If it works or there is a solution I don’t know about it.

1 Like

I could work cocos2dx v3.17.2 :+1:t5: I just followed usual steps for installment and create project

@Algoritmiik I don’t understand, are you saying 3.17.2 works with M1 out of the box?

1 Like

yes you can but it makes an x86_64 build. I think @slackmoehrle is saying that you cant build for apple silicon (arm64) and he’s right.

1 Like

I’m not sure if you can build for M1 or not but yes 3.17.2 just working on M1. I guess @bilalmirza is right about x86_64 and M1 builds

1 Like

hello i can’t able run my cocos 2dx project in new macmini m1… i am
sharing ss for ref.


i am using cocos2dx version3.17.2 and xcode Version 13.0 (13A233).

so please guys help me @smitpatel88 @slackmoehrle @bilalmirza @Algoritmiik @pinky2012 @vkreal2

1 Like

It looks like you’re building for the iOS simulator, and in that case, do not build for ARM, but build for x86_64, since the simulators work for that architecture (even on the M1 Mac).

Hello @R101 thank you for your kind response… i added the x86_64. but still getting same error attaching ref. ss. please please do help me to get resolve this…! thank you

If it’s an iOS simulator build, then you cannot have arm64 and armv7 in the VALID_ARCHS list. It must only be x86_64.

If you’re using cmake to create your iOS simulator build, then add this in the root CMakeLists.txt of your project, which will set the correct architecture just for the simulator build:

if(APPLE)
    set_target_properties(${APP_NAME} PROPERTIES
        XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] x86_64
        XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] x86_64
        )    
endif()