[转载]Building Cocos2d-x on RHEL / Fedora / CentOS Linux

This guide is intended to help anyone who wishes to build Cocos2d-x from source on an RPM-based Linux machine (RHEL / Fedora / CentOS). At the time these instructions were tested, Cocos2d-x v2.2.1 was used on Fedora 19.

For RPM-based systems, there are some issues with the archive you get fromhttp://www.cocos2d-x.org/download. If you look closely at the install-deps-linux.sh file, you will notice the deb-based package manager commands, like ‘dpkg-query’ and ‘apt-get’ which indicate this release was intended for Debian-based systems. There is another issue related to the dependency of Cocos2d-x on the GLFW package. If you have already tried to build, you may have received a make error stating “GL/glfw.h: No such file or directory”. Although glfw and glfw-devel are currently available through the Fedora 19 repos, they do not match the version Cocos2d-x needs for compiling and linking. We will instead have to download a legacy version of glfw, build it, then refer to this version of glfw when building Cocos2d-x.

To summarize, we will be obtaining as many of the required packages we can via the Fedora or EPEL repositories and then building two packages from source: glfw-legacy and Cocos2d-x. I am assuming you will build these two packages in your home directory, and this guide is structured as such.

Let us begin by installing some prerequisite packages via YUM. Issue the terminal command (answer yes if YUM displays additional dependencies):

yum install libX11-devel libXmu-devel libXi mesa-libGLU mesa-libGLU-devel glew glew-devel libcurl libcurl-devel fontconfig fontconfig-devel

Now we will acquire and build glfw-legacy. Download the GLFW legacy source from Git Hub (git required) using the terminal command from your home directory:

git clone https: //github .com /glfw/glfw-legacy .git

This will create the directory ~/glfw-legacy. Descend into this directory and build the package by issuing the command:

make x11

Since we have the glfw-legacy binaries built, we can move on and begin working with the Cocos2d-x package. Download the Cocos2d-x v2.2.1 source from http://www.cocos2d-x.org/download. Extract the cocos2d-x-2.2.1 directory from the archive into your home directory. Before we can build, we need to point the Cocos2d-x make instructions to the correct glfw-legacy headers and binaries.

Locate the make file ~/cocos2d-x-2.2.1/cocos2dx/proj.linux/cocos2dx.mk and perform the following modifications:

Add 2 constants called GLFW_LEGACY_ROOT and GLFW_LEGACY_LIB_DIR (placement right after after COCOS_SRC, line 21 would be appropriate) and define them as:

GLFW_LEGACY_ROOT = $(HOME) /glfw-legacy
 
GLFW_LEGACY_LIB_DIR = $(GLFW_LEGACY_ROOT) /lib/x11

Now append one line to the INCLUDES variable (do not forget to escape the end of the previous line by appending a space and a backslash):

-I$(GLFW_LEGACY_ROOT) /include

That will take care of the glfw-legacy headers needed for compiling. We now have to resolve the linking of the glfw-legacy binaries. In this case, we have a single shared object libglfw.so located in ~/glfw-legacy/lib/x11. Inside the cocos2dx.mk file, locate the line that matches:

SHAREDLIBS += -lglfw -lGLEW -lfontconfig -lpthread -lGL

Change it by inserting the glfw-legacy library directory before the link to libglfw:

SHAREDLIBS += -L$(GLFW_LEGACY_LIB_DIR) -lglfw -lGLEW -lfontconfig -lpthread -lGL

The alterations are now complete. Save the changes, then navigate to your ~/cocos2d-x-2.2.1 directory and issue the top level make command, simply:

make

In order to run the sample programs that are now built as part of the cocos2d-x package, we will need to have libcocos2d.so and libglfw.so in our library path. A simple way to achieve this is by appending the respective library directories to our LD_LIBRARY_PATH variable with the terminal command:

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${HOME} /cocos2d-x-2 .2.1 /lib/linux/release :${HOME} /glfw-legacy/lib/x11

For convenience, the export command listed above can be added to your .profile or.bashrc file to avoid having to retype in the future.

猜你喜欢

转载自udvlin.iteye.com/blog/2001924