Can't run cocos2d-x on M1 Chip

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()

if i am added only one x86_64 then getting these errors…


Screenshot 2021-10-04 at 5.56.05 PM

1 Like

i did following changes. can’t able to run in simulator… i am sharing ss for ref.Screenshot 2021-10-05 at 10.02.01 AM


Screenshot 2021-10-04 at 5.56.05 PM

@R101 i am sharing all my ss…Screenshot 2021-10-04 at 5.56.05 PM
Screenshot 2021-10-05 at 10.02.01 AM

please help me.

@AGamer I am not sure whether M1 is supported or not.
But for your error I think you need to exclude arm64 for iOS simulator.


This is how we handle for xcode 12.4 and its working for us.
Edit:
May be you need to delete VALID_ARCHS whole entry as well.

If you search in build_settings then you should not see anything.
After this only it worked for me.
Not sure for M1 machines though.

I’ve seen that error before, but I can’t quite remember why it happens. Did you clear you build folder, or at least delete [build folder]/CMakeCache.txt, after changing the settings in your CMakeLists.txt?

It could be a problem with the cocos2d/cmake/ios.toolchain.cmake file, in terms of what settings it has. Open it up and see if there’s anything obvious in there, and compare it to a working version.

@smitpatel88 thank you for your kind response & support. i already did all these steps… but not working in m1 may be…but i am trying to resolve this…

@R101 please can you put a full video for all these changes? because i did some change but honestly i did not understand what more change i have to do in CMakeLists.txt. so please can you put small video link it’s really needful to all who are using m1… thanks again @smitpatel88 @R101

@smitpatel88 @slackmoehrle @bilalmirza @Algoritmiik @vkreal2 @R101 thank you all for your response… finally i can run my cocos2dx project on xcode 13 in mac m1 with big sur…

i am attaching all screenshot how i can run you can refer it also if you have any query please let me know

Screenshot 2021-10-09 at 6.36.28 PM
Screenshot 2021-10-09 at 6.36.55 PM
Screenshot 2021-10-09 at 6.37.02 PM
Screenshot 2021-10-09 at 6.37.28 PM


Screenshot 2021-10-09 at 7.17.22 PM

1 Like

@AGamer can you please share all the changes you have made to make M1 work?

@vkreal2 yes… definitely, follow all beloved steps.

  1. force quite xcode right click it and tick-mark “open using rosetta” se above screenshot.
  2. change excluded architectures and valid architectures as per the screenshot in build setting in xcode.
  3. put version code(number) whatever you want as mentioned in screenshot.
  4. in (search in xcode) btvector3.h replace line
    #define BT_SHUFFLE(x,y,z,w) ((w)<<6 | (z)<<4 | (y)<<2 | (x))” with following line
    #define BT_SHUFFLE(x, y, z, w) (((w) << 6 | (z) << 4 | (y) << 2 | (x)) & 0xff)”

those all are valid steps you can execute for m1…and it’a absolutely running perfect…

thanks.

1 Like

I have asked our engineering team how we could go about testing this. I don’t know what their process will be.

@AGamer i assume that you compiled all of the 3rd party libs for M1?

The solution presented by @AGamer is a work-around, and should only be considered to be a temporary measure. The files are being compiled as the x86_64 architecture, and use Rosetta to work on hardware with ARM instruction-set processors.

The actual solution should be to build native libraries for ARM, as @pinky2012 mentioned earlier up in this thread.

In terms of iOS simulator support, x86_64 is the way to go, since providing ARM-specific simulator libraries is more effort than it’s worth, and the x86_64 version of the simulators work perfectly on the M1 chip.

4 Likes