ubuntu 10.04运行cocos2d-x 3.x

最近在研究cocos2d-x,下载下来之后,要在ubuntu上跑起来费了一番功夫。总结以下:

1、下载代码

$ git clone [email protected]:cocos2d/cocos2d-x.git


2、搭建环境

    $ cd cocos2d-x/build
    $ ./install-deps-linux.sh

3、安装cmake版本和gcc g++版本

要求:

cmake版本:2.8.0
gcc g++版本:4.8.1


4、编译

$ cmake ..
$ make


cmake的时候,ubuntu 10.04很可能遇见如下错误:


CMake Error at CMakeLists.txt:30 (cmake_policy):
  Policy "CMP0017" is not known to this version of CMake.
...
CMake Error at cmake/Modules/CocosBuildHelpers.cmake:44 (find_package):
  Could not find module FindGLEW.cmake or a configuration file for package
  GLEW.
...
CMake Error at cmake/Modules/FindPkgConfig.cmake:163 (include):
  include could not find load file:


    /FindPackageHandleStandardArgs.cmake
...


第二个错误中:glew相关的包都已经安装了。
我从android的代码下找了一个FindGLEW.cmake文件,放到了cmake/Modules下面


其他两个错误,我是这样改的:
@@ -27,7 +27,8 @@ cmake_minimum_required(VERSION 2.8)
 # It ensures that when Find*.cmake files included from cmake's Modules dir
 # include another *.cmake file with relative path, that file will be included
 # also from cmake's Modules dir, to not clash with per-project files.
-cmake_policy(SET CMP0017 NEW)
+#cmake_policy(SET CMP0042 NEW)
+cmake_policy(VERSION 2.8)
 
 project (Cocos2d-X)
 
@@ -37,6 +38,8 @@ set(COCOS2D_X_VERSION 3.3.0-rc1)
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
 include(CocosBuildHelpers)
 
+set(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
+
 message(${BUILDING_STRING})
 
 set(USE_WEBP_DEFAULT ON)




修改之后cmake不报错,make的时候报错,编译glfw报错:
看报错的信息应该是glfw的版本不对,要去glfw3,但是我电脑上是glfw2


但是apt-get无法安装glfw3,许是ubuntu版本不够高,于是我到glfw.org网站上下了一份glfw3的源代码,然后自己编译。

http://www.glfw.org/docs/latest/compile.html#compile_cmake


然后编译还会报如下错误:

../../lib/libcocos2d.a(CCGLViewImpl-desktop.cpp.o): In function `cocos2d::GLViewImpl::GLViewImpl()':
/home/yinlijun/project/google-code/cocos2d-x/cocos/platform/desktop/CCGLViewImpl-desktop.cpp:287: undefined reference to `glfwSetErrorCallback'
../../lib/libcocos2d.a(CCGLViewImpl-desktop.cpp.o): In function `cocos2d::GLViewImpl::initWithRect(std::string const&, cocos2d::Rect, float)':
/home/yinlijun/project/google-code/cocos2d-x/cocos/platform/desktop/CCGLViewImpl-desktop.cpp:348: undefined reference to `glfwWindowHint'
/home/yinlijun/project/google-code/cocos2d-x/cocos/platform/desktop/CCGLViewImpl-desktop.cpp:349: undefined reference to `glfwWindowHint'
/home/yinlijun/project/google-code/cocos2d-x/cocos/platform/desktop/CCGLViewImpl-desktop.cpp:350: undefined reference to `glfwWindowHint'
/home/yinlijun/project/google-code/cocos2d-x/cocos/platform/desktop/CCGLViewImpl-desktop.cpp:351: undefined reference to `glfwWindowHint'
/home/yinlijun/project/google-code/cocos2d-x/cocos/platform/desktop/CCGLViewImpl-desktop.cpp:352: undefined reference to `glfwWindowHint'
../../lib/libcocos2d.a(CCGLViewImpl-desktop.cpp.o):/home/yinlijun/project/google-code/cocos2d-x/cocos/platform/desktop/CCGLViewImpl-desktop.cpp:353: more undefined references to `glfwWindowHint' follow


这时应该把本地的glfw2版本完全删除。:

sudo apt-get remove XXX


这还没完,编译到cpp-empty-test的时候,还会报错:

Linking CXX executable ../../bin/cpp-empty-test/cpp-empty-test
/bin/sh: cannot create /Resources: Permission denied
make[2]: *** [bin/cpp-empty-test/cpp-empty-test] 错误 2
make[1]: *** [tests/cpp-empty-test/CMakeFiles/cpp-empty-test.dir/all] 错误 2
make: *** [all] 错误 2


需要修改如下:

yinlijun@brn-yinlijun:cocos2d-x$ git diff tests/cpp-empty-test/CMakeLists.txt
diff --git a/tests/cpp-empty-test/CMakeLists.txt b/tests/cpp-empty-test/CMakeLists.txt
index fa3f9ab..23daef4 100644
--- a/tests/cpp-empty-test/CMakeLists.txt
+++ b/tests/cpp-empty-test/CMakeLists.txt
@@ -75,8 +75,13 @@ else()
   set_target_properties(${APP_NAME} PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY  "${APP_BIN_DIR}")
   add_custom_command(TARGET ${APP_NAME} POST_BUILD
-    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources $<TARGET_FILE_DIR:${APP_NAME}>${RES_PREFIX}
+    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Resources ${APP_BIN_DIR}${RES_PREFIX}
+    #$<TARGET_FILE_DIR:${APP_NAME}>${RES_PREFIX}
     )






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章