I have almost succesfully compiled Cocos2d-x on my Raspberry, but here is what I had to do:
Optional: Use QEmu with a lot of extra space and more memory via a swapfile to compile faster.
Use a clean Raspbian image, execute all code here on the Raspberry Pi itself:
For prequisites install these packages (notice there’s GIT at the end, which could be prevented if you just copy the source archive to your RPi):
sudo apt-get install libx11-dev libxmu-dev libgl2ps-dev g++ libcurl4-gnutls-dev libfontconfig1-dev libsqlite3-dev libglew*-dev libgl1-mesa-dev libglfw-dev freeglut3-dev libzip-dev git
Get the latest source package of Cocos2d-x:
git clone https://github.com/cocos2d/cocos2d-x.git
install RPi versions of libraries needed by Cocos2d-x:
sudo apt-get install libfreetype-dev libpng-dev libjpeg-dev libtiff-dev libwebp-dev
I don’t know whether this is needed (I think it is not, actually) but I copied all the resulting library .a files to
./cocos2dx/platform/third_party/linux to be sure the Raspberry Pi versions were linked into the build.
install libopenal on RPi
sudo apt-get install libopenal-dev libalut-dev libvorbis-dev
Tricky part here, this should actually be done in a new proj.raspberrypi copied from proj.linux. The problem is that Cocos2d-x uses FMod for the Linux build, which is not available for Raspberry Pi. So we change the
./CocosDenshion/proj.linux/Makefile to make sure Cocos2D uses Blackberry’s OpenAL code for sound:
SOURCES = ../blackberry/SimpleAudioEngine.cpp
Next problem was an error with libfreetype.a, which can be safely removed as far as I know now. As long as we only used real bitmapfonts, this is not yet a problem for now, so remove the dependency on libfreetype in
#STATICLIBS = \$/libfreetype.a STATICLIBS = \$/libpng.a \$/libjpeg.a \$/libtiff.a \$/libwebp.a
And, in the same file, comment out this part to remove FMod dependencies:
#FMOD_LIBDIR = \$/CocosDenshion/third_party/fmod/lib64/api/lib
#SHAREDLIBS += ~~lfmodex64
#FMOD_LIBDIR = \$/CocosDenshion/third_party/fmod/api/lib
Then change the following part in the same file to bind to OpenAL and ALUT libraries for sound:
#SHAREDLIBS +=~~L\$ ~~Wl,~~rpath,\$/\$
Next, I encountered a bug in
./cocos2dx/kazmath/include/kazmath/neon_matrix_impl.h when it tried to include “arm/arch.h”. From what I understood, this include is only used for the
__arm__ definition, which is already available when compiling for Raspberry Pi anyway, so somment it out:
Now the cocos2d libraries at least compile, but compiling the first HelloCPP example results in a LOT of “unresolved reference to…” libjpeg, libpng etc. libraries, though theyare* added as static libraries in the make files. I have no clue yet how to prevent this error from happening.
Now the biggest challenge is left: Port the OpenGL code to use OpenGLES2 calls, since this is what is supported by Raspberry Pi. Perhaps again the Blackberry code can help us out here, but I haven’t arrived there yet. I read somewhere this piece of text of someone who merged Bada code into Linux for this: “put the bada gl view code into linux and it worked…also wid some tweaks…changed initializing of openGLES to Null Windowing System,direct frame buffer that is.”. Let’s hope this part is not that hard… Who can help us out further here?