Configure/compile/run the Cocos2dx project in Ubuntu
For project reasons, you need to put a project using cocos2dx in Linux to run (in Windows, you can use VS to write it normally), and debug it for about 3 ~ After four hours, the project was finally running. Record the precautions here to help you avoid making the same mistakes.
I use Ubuntu kylin 14.04 and cocos2dx 2.2.3.
The project file is as follows:
The file package that contains cocos2dx is included in projects.
The projects folder contains the following content:
The Classes folder contains the source file of the project, including some. h and. cpp source code.
The Resources folder contains the project resource files, including some images and text.
The focus of our attention is the proj. linux folder, which contains the following content:
Main. cpp is the main function of the project, including calling the upper-layer classes file.
Both the build. sh and makefile files are for project compilation and are the important part of our attention.
My makefile file is as follows for your reference only:
EXECUTABLE = TheDemo
Primary des =-I ../\
-I ../../\
-I ../Classes \
-I $ (COCOS_ROOT)/CocosDenshion/include \
-I $ (COCOS_ROOT)/extensions /\
-I $ (COCOS_ROOT)/external /\
-I $ (COCOS_ROOT)/external/chipmunk/include/chipmunk
// Note that all project files should be included here. For me, it is the content of the classes folder mentioned above.
SOURCES = main. cpp \
../Classes/AppDelegate. cpp \
../Classes/HelloWorldScene. cpp \
../Classes/eventManager. cpp \
../Classes/GameData. cpp \
../Classes/GameScene. cpp \
../Classes/levelselect. cpp \
../Classes/MyNodes. cpp
COCOS_ROOT = ../../..
Include $ (COCOS_ROOT)/cocos2dx/proj. linux/cocos2dx. mk
// Here are some lib files and library files, which are written by reference to the cocos2dx sample project. It is a waste of time for this.
SHAREDLIBS + =-lcocos2d-lcocosdenshion-lcurl-lpthread
COCOS_LIBS = $ (LIB_DIR)/libcocos2d. so $ (LIB_DIR)/libcocosdenshion. so
STATICLIBS + = \
$ (LIB_DIR)/libextension. \
$ (LIB_DIR)/libbox2d. \
$ (LIB_DIR)/libchipmunk.
$ (TARGET): $ (OBJECTS) $ (STATICLIBS) $ (COCOS_LIBS) $ (CORE_MAKEFILE_LIST)
@ Mkdir-p $ (@ D)
$ (LOG_LINK) $ (CXX) $ (CXXFLAGS) $ (OBJECTS)-o $ @ $ (SHAREDLIBS) $ (STATICLIBS)
$ (OBJ_DIR)/%. o: %. cpp $ (CORE_MAKEFILE_LIST)
@ Mkdir-p $ (@ D)
$ (LOG_CXX) $ (CXX) $ (CXXFLAGS) $ (DES) $ (DEFINES) $ (VISIBILITY)-c $ <-o $ @
$ (OBJ_DIR)/%. o: ../%. cpp $ (CORE_MAKEFILE_LIST)
@ Mkdir-p $ (@ D)
$ (LOG_CXX) $ (CXX) $ (CXXFLAGS) $ (DES) $ (DEFINES) $ (VISIBILITY)-c $ <-o $ @
Note that, during compilation and linking, files cannot be matched or missing. When project files and library files are complete, most of them are makefile files that are not written to each other. There are no file directories or lib files missing. Pay attention to this situation.
If the command line operation is troublesome, it is a good choice to use IDE, because it is not very familiar with ubuntu. During the learning process, debugging this project uses Netbeans 8.0.2, it seems to be easy to use.
Attached to a successfully run:
In the future, we will have a better understanding of Linux ~
6. Run as Android Application. An apk file is generated in the bin directory of proj. android, and the transplantation is complete.
-------------------------------------- Split line --------------------------------------
New Milestone: Cocos2d-x v3.0 official version released!
Cocos2d basics and basic functions
How to Adapt Cocos2d to Android
Analyzing the implementation of Action in Cocos2d-x
Ubuntu Cocos2d-x development environment construction and Configuration
-------------------------------------- Split line --------------------------------------