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}
     )






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