build environment
Hardware: macbook pro quad-core Intel Core i7
System: macOS Big Sur 11.4.2, xcode Version 13.1, cmake 3.20.5
Software: iterm2 Build 3.4.8, zsh 5.8, python 2.7.16
cocos2d-x v4: official download package http://cocos2d-x.org/filedown/cocos2d-x-v4.0
PS: The official recommended configuration is as follows v4.0 environment requirements
build steps
Step 1: After parsing the zip package, enter the cocos2d-x-4.0 directory and execute the setup.py script
Step 2: Update the environment variables, and source the .zshrc file according to the prompt, that is, update the cocos-related environment variables and configuration to the current shell
Step 3: Use the cocos command to create an IOS Demo project (the Demo project copies the cocos source code in the current directory and creates an IOS APP Demo that depends on the source code)
cocos new MyGame -p com.your_company.mygame -l cpp -d /Users/luogw/shell_temp/demo
Step 4: Enter the Demo directory, create a build folder, and CD to this folder (~/shell_temp/MyGame/build) and execute the following build command
cocos run --proj-dir .. -p ios
Encounter problems
执行命令出错,返回值:65。
Seeing that ld is a link error, first check whether an IOS APP project is generated normally, open and compile it with xocde
find the reason
Go to the ios-build of the Demo project MyGame, we see MyGame.xcodeproj, that is, use xcode to open and compile to see the error situation
solution
/usr/lib/libiconv.dylib 改成 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libiconv.dylib
/usr/lib/libz.dylib 改成 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libz.dylib
即两个库的路径加上 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/
The changed configuration is as follows
Build successfully and start Demo!