How to run HelloWorld and tests on linux

Version 23 (Minggo Zhang, 2011-12-22 19:23)

1 1 Minggo Zhang
h1. How to run HelloWorld and tests on linux
2 1 Minggo Zhang
3 18 Minggo Zhang
cocos2d-x supports linux platform from cocos2d-1.0.1-x-0.9.2.
4 18 Minggo Zhang
This document will describe how to run HelloWorld and tests on linux and android simulator. 
5 1 Minggo Zhang
6 18 Minggo Zhang
The enviroment is ubuntu 11.04 + eclipse3.7. 
7 18 Minggo Zhang
8 1 Minggo Zhang
h2. 1. Set up environment
9 1 Minggo Zhang
10 15 Minggo Zhang
h3. 1.1 get cocos2d-x source code
11 15 Minggo Zhang
12 1 Minggo Zhang
a) get latest code from git, it is not stable
13 18 Minggo Zhang
<pre>git clone https://github.com/cocos2d/cocos2d-x.git</pre>
14 1 Minggo Zhang
b) get released version, it is stable
15 21 Minggo Zhang
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Download
16 15 Minggo Zhang
17 18 Minggo Zhang
h3. 1.2.  install android sdk, use eclipse as IDE
18 15 Minggo Zhang
19 9 Minggo Zhang
Refer the link to install android sdk http://developer.android.com/sdk/index.html
20 8 Minggo Zhang
*Use this appoach to install jdk*
21 1 Minggo Zhang
<pre>
22 1 Minggo Zhang
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
23 1 Minggo Zhang
sudo apt-get update
24 1 Minggo Zhang
sudo apt-get install sun-java6-jdk
25 1 Minggo Zhang
</pre>
26 15 Minggo Zhang
27 15 Minggo Zhang
h3. 1.3. install cdt for eclipse to compile c/c++ codes in eclipse
28 15 Minggo Zhang
29 1 Minggo Zhang
Help -> Install New Software... -> Add...
30 8 Minggo Zhang
!install_cdt.jpg!
31 15 Minggo Zhang
32 11 Minggo Zhang
The link of cdt is http://download.eclipse.org/tools/cdt/releases/helios.
33 15 Minggo Zhang
34 23 Minggo Zhang
h3. 1.4. install needed libs
35 15 Minggo Zhang
36 7 Minggo Zhang
<pre>sudo apt-get install  libgl1-mesa-dev libglfw-dev freeglut3-dev libzip-dev</pre>
37 7 Minggo Zhang
If you meet problem as me, maybe you should run the command before installing the libs
38 7 Minggo Zhang
<pre>sudo apt-get -f</pre>
39 7 Minggo Zhang
40 7 Minggo Zhang
h2. 2. Run with makefile
41 7 Minggo Zhang
42 20 Minggo Zhang
First, build all libraries
43 20 Minggo Zhang
<pre>
44 20 Minggo Zhang
cd $COCOS2DX
45 20 Minggo Zhang
./build_linux.sh
46 20 Minggo Zhang
</pre>
47 20 Minggo Zhang
COCOS2DX is the root of the cocos2d-x.
48 20 Minggo Zhang
49 16 Minggo Zhang
It is simple to run with makefile
50 16 Minggo Zhang
<pre>
51 16 Minggo Zhang
cd $HELLOWORLD/linux/
52 16 Minggo Zhang
make
53 16 Minggo Zhang
./HelloWorld
54 16 Minggo Zhang
</pre>
55 16 Minggo Zhang
56 1 Minggo Zhang
HELLOWORLD is the root of helloworld, in my environment it is /home/zhangxm/cocos2d-x/HelloWorld.
57 20 Minggo Zhang
You can run tests in the same way. It is simple, isn't it?
58 16 Minggo Zhang
59 7 Minggo Zhang
h2. 3. Run with eclipse
60 1 Minggo Zhang
61 12 Minggo Zhang
First, import existing projects: File -> Import...
62 12 Minggo Zhang
!import_project.jpg!
63 12 Minggo Zhang
64 12 Minggo Zhang
Then select the directory of the root of cocos2d-x
65 12 Minggo Zhang
!select_project.jpg!
66 12 Minggo Zhang
67 7 Minggo Zhang
Now, you can build and run HelloWorld and tests.
68 13 Minggo Zhang
* build
69 17 Minggo Zhang
Right click the project of HelloWorld -> Build Project
70 17 Minggo Zhang
* run
71 17 Minggo Zhang
Right click the project of HelloWorld -> Run as -> Local c/c++ Application
72 17 Minggo Zhang
73 2 Minggo Zhang
You can run tests in the same way.
74 19 Minggo Zhang
75 19 Minggo Zhang
h2. 4. Run on android emulator
76 19 Minggo Zhang
77 23 Minggo Zhang
Please refer [[How to build and run HelloWorld]].