Cocos2d-x v4 iOS Xcode build causes Undefined symbols for architecture errors

I’m struggling with cocos2d-x v4 for iOS game developing.

I’m using Xcode 12.1.

I created cocos2d-x project like below.

cocos new TestGame -p com.example.testgame -l cpp -d /ProjectDir

Then, I created a Xcode project like below.

cd /ProjectDir/TestGame
mkdir ios-build
cd ios-build/
cmake .. -GXcode -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos

Then, open the Xcode project and build it to run on my device, the cocos2d-x v4 project run perfectly.

Next, I run this project on simulator, the cocos2d-x v4 project run perfectly.

But, when I run the project again on my device, the build fails.

It shows many warnings like below.

ld: warning: ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_recast.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libexternal.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libcocos2d.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_tinyxml2.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_xxtea.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_xxhash.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_clipper.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_edtaa3func.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_convertUTF.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_poly2tri.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_md5.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Debug/libext_unzip.a, building for iOS-arm64 but attempting to link with file built for iOS Simulator-x86_64

and show many errors like below (This is one example of many errors.)

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_CCEAGLView", referenced from:
      objc-class-ref in RootViewController.o
  "cocos2d::GLViewImpl::_multisamplingCount", referenced from:
      -[RootViewController loadView] in RootViewController.o
  "cocos2d::Application::getInstance()", referenced from:

Why these static libraries not generated properly? And how to fix it?
If I clean the build files, and run again on the device, It’s OK, but It takes too much time, so I want to know other realistic way.

Next, I thought about releasing the App.
To release the app, I set “Build Active Architecture Only” from “Yes” to “No” in Build Settings.
Then I run the project on my device.

Similar warning appeared.

ld: warning: ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libcocos2d.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libexternal.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_recast.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_tinyxml2.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_xxhash.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_xxtea.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_edtaa3func.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_convertUTF.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_clipper.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_md5.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_poly2tri.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

ld: warning: ignoring file /ProjectDir/TestGame/ios-build/lib/Release/libext_unzip.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64

also errors like below (This is one example of many errors.)

Undefined symbols for architecture armv7:
  "cocos2d::GLViewImpl::_multisamplingCount", referenced from:
      -[RootViewController loadView] in RootViewController.o
  "_OBJC_CLASS_$_CCEAGLView", referenced from:
      objc-class-ref in RootViewController.o
  "cocos2d::Application::getInstance()", referenced from:

Why these static library only contains one architecture?
And How to solve it for archive build?

I’m really confusing. I want to release cocos2d-x v4 games.

Please help.

Thank you.

Just a quick thought, are you sure you’ve changed “Build Active Architecture Only” in all the targets (cocos2dx targets too, not only your game’s target)?

1 Like

Thank you for your reply.

Wow, you are right!
I did’t think that I need to change all the targets.

I changed “Build Active Architecture Only” from “Yes” to “No” in PROJECT and all the TARGETS (cocos2d,ext_clipper, ext_convertUTF, ext_edtaa3func, ext_md5, ext_poly2tri, ext_recast, ext_tinyxml2, ext_unzip, ext_xxxhash, ext_xxtea, external) then built it, it worked.

Thank you so much!
Now, the second question is solved.

I still need help for the first question. (Why these static libraries not generated properly for device build after simulator build.)

when Building for iOS Simulator it uses Mac architecture (x86_64) not device architecture (arm64).

You can also add build setting VALID_ARCHS and input value x86_64, when you use simulator to debug.

i tried but getting errors… attaching ss for ref.


Screenshot 2021-10-04 at 5.56.05 PM