在Linux上运行Cocos2d-x安装目录中的示例游戏
原创
©著作权归作者所有:来自51CTO博客作者WongKyunban的原创作品,请联系作者获取转载授权,否则将追究法律责任
Cocos2d-x在ubuntu上的开发环境搭建,请参考《Ubuntu18.04搭建Cocos2d开发环境》
我的Cocos2d-x的安装目录在:/home/kyun/Desktop/coco2dx/cocos2d-x-4.0:
示例代码所在位置:/home/kyun/Desktop/coco2dx/cocos2d-x-4.0/tests:
编译Cocos2d-x安装目录下的示例代码
~$ cd /home/kyun/Desktop/coco2dx/cocos2d-x-4.0
~/Desktop/coco2dx/cocos2d-x-4.0$ mkdir -p build/linux-build
~/Desktop/coco2dx/cocos2d-x-4.0$ cd build/linux-build
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build$ cmake ../..
- 当cmake结束后,~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build目录就会有相应生成的文件有目录:
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build$ tree -L 1.
├── bin
├── CMakeCache.txt
├── CMakeFiles
├── cmake_install.cmake
├── engine
├── lib
└── Makefile
- 运行make命令编译,编译时间会稍微长一点
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build$ make -j 4
make编译完成后,所有的东西都会生成在 ~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build/bin目录里 :
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build$ cd bin
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build/bin$ tree -L 1
.
├── cpp-empty-test
├── cpp-tests
├── HelloCpp
├── lua-empty-test
└── lua-tests
5 directories,
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build$ cd bin/cpp-tests
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build/bin/cpp-tests$ ./cpp-tests
Ready for GLSL
Ready for OpenGL 2.0
Console: IPV4 server is listening on 0.0.0.0:5678
以上就是在ubuntu18.04操作系统上,编译运行Cocos2d-x-4.0安装目录下的示例游戏的全过程。
在运行
~/Desktop/coco2dx/cocos2d-x-4.0/build/linux-build/bin/cpp-tests$ ./cpp-tests
你可能会遇到以下异常:
./cpp-tests: error while loading shared libraries: /home/kyun/Desktop/coco2dx/cocos2d-x-4.0/external/linux-specific/fmod/prebuilt/64-bit/libfmod.so.6: file too short
请参考《Cocos2d-x异常external/linux-specific/fmod/prebuilt/64-bit/libfmod.so.6: file too short》
谢谢阅读