Skip to content

Instantly share code, notes, and snippets.

@codexico
Last active April 27, 2024 20:25
Show Gist options
  • Save codexico/6126f9bb6e60af9ba9ec441cdc9ef2b2 to your computer and use it in GitHub Desktop.
Save codexico/6126f9bb6e60af9ba9ec441cdc9ef2b2 to your computer and use it in GitHub Desktop.
install cocos on ubuntu 16.04
sudo apt-get update
sudo apt-get upgrade
# 1) Download from source, the zip from the site has problems on linux
# https://github.com/cocos2d/cocos2d-x/pull/15958#issuecomment-228919359
git clone https://github.com/cocos2d/cocos2d-x.git
cd cocos2d-x
# 2016-06-27 branch master is broken, change to commit 04d3550
git checkout 04d3550
# 2) Install
# https://github.com/cocos2d/cocos2d-x
python download-deps.py
git submodule update --init
./setup.py
source ~/.bashrc
# https://www.youtube.com/watch?v=mc8ip48oivQ
cd build
./install-deps-linux.sh
cmake ..
make
# simple test
bin/cpp-empty-test/cpp-empty-test
# fix libfmod.so.6
# https://github.com/cocos2d/cocos2d-x/issues/14961#issuecomment-180736077
# copy
sudo cp /external/linux-specific/fmod/prebuilt/64-bit/libfmod.so /usr/local/lib/
sudo cp /external/linux-specific/fmod/prebuilt/64-bit/libfmodL.so /usr/local/lib/
# create symbolic link in /usr/local/lib/
ln -s libfmod.so libfmod.so.6
# run again (in cosos2d/build)
./install-deps-linux
# more tests
# cd cocos2d-x
bin/cpp-tests/cpp-tests
# 3) create project
cocos new GameName -l cpp -d ~/projs/GameName/src
# 3.1) If existing project, copy Classes and Resources and then edit CMakeList.txt
# http://discuss.cocos2d-x.org/t/run-a-project-linux-error-createscene/18368
# set(GAME_SRC
# proj.linux/main.cpp
# Classes/AppDelegate.cpp
# Classes/HelloWorldScene.cpp
# Classes/NewScene.cpp
# Classes/Vampire.cpp
# Classes/VampireGame.cpp
# )
# 4) Run
# 4.1) command line
cocos run -p linux
# 4.2) run with netbeans
sudo apt-get install netbeans
# Tools > Plugins > Settings ]
# > add Update Centers
# > Available Plugins C/C++
# http://www.cocos2d-x.org/wiki/How_to_run_cpp-tests_on_Linux_Netbeans
# File -> New Project
# Category -> C/C++ and Projects: C/C++ Project With Existing Sources
# Browse and select your source tree
# NetBeans will recognise it is a `CMake` based project and setup the rest for you
# Build Project (from toolbar)
# Run Project (from toolbar)
# 4.3) run with codeblocks
# https://www.youtube.com/watch?v=gwDdUspNMvg
# create and run
sudo apt-get install codeblocks
cocos new FirstGameTest -p com.codexico.gametest -l cpp -d ~/projs/
cd ~/projs/FirstGameTest
cmake -G 'CodeBlocks - Unix Makefiles'
# open MyGame.cbp
# build
# MyGame > Properties > Build Targets >
# Type: Console application
# Output filename: linux-build/bin/MyGame
# then
rm -rf linux-build
# and build again, using some IDE or
cocos run -p linux
@Kishy-nivas
Copy link

Thanks a lot ,nothing worked from the official cocos2d zip file .

@leosh64
Copy link

leosh64 commented Feb 15, 2019

Hey, thanks for this tutorial! I'm having some trouble though, at the final step of compilation I constantly get this error:

[100%] Linking CXX executable bin/GameName/GameName
/usr/bin/ld: ../cocos2d/external/freetype2/prebuilt/linux/64-bit/libfreetype.a(ftbase.linux64.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC

Any idea how to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment