在pc端osg已經證明了他的實力了,大量的擴充項目、嚴格的跨平台。在移動端目前還沒有一個很好的3D開源架構可以使用,開發人員需要從0開始寫很費事,構建這樣一個平台也非一日之功,將其編譯到移動平台則來的簡單了。一下是在幾日來構建過程中遇到的一些問題,比較頻繁的,已解決,分享一下。
首先簡單介紹一下我在構建時使用的一些工具:
1、作業系統:Win764位旗艦
2、組態工具:CygWin32位版及其提供的32位的cmake
3、構建工具:Cygwin32位下的make工具(3.8.92)
4、NDK:r9b
5、sdk api:android-19
6、Eclipse:adt-bundle-windows-x86-20131030內建的
osg用的3.2.0的,因為這是目前較為穩定的一個主幹版本,一般情況下不需要改動代碼。我直接就編譯了在pc上根本沒測試,最後編譯完成運行例子的時候有一點小瑕疵,後面介紹吧。
第三方庫用的是osg官網上介紹的那個,雖然我們可以自己搞定,但是對於我這種新手來說將就著用吧。
構建命令:
cmake .. -DOSG_BUILD_PLATFORM_ANDROID=ON -DDYNAMIC_OPENTHREADS=OFF -DDYNAMIC_OPENSCENEGRAPH=OFF -DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF -DOSG_GL_MATRICES_AVAILABLE=ON -DOSG_GL_VERTEX_FUNCS_AVAILABLE=ON -DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=ON -DOSG_GL_FIXED_FUNCTION_AVAILABLE=ON -DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF -DOSG_GL1_AVAILABLE=OFF -DOSG_GL2_AVAILABLE=OFF -DOSG_GL3_AVAILABLE=OFF -DOSG_GLES1_AVAILABLE=ON -DOSG_GLES2_AVAILABLE=OFF -DJ=4 -DANDROID_PLATFORM=8 -DANDROID_STL="gnustl_static" -DCMAKE_INSTALL_PREFIX={path to folder you want to put your libs and headers}
為什麼我在介紹構建工具的時候要說明系統和工具的字長呢?話說我在構建時用了一個64位的cygwin構建了半天都是
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 4.8.2
CMake Warning at /usr/share/cmake-2.8.11.2/Modules/Platform/CYGWIN.cmake:15 (message):
CMake no longer defines WIN32 on Cygwin!
(1) If you are just trying to build this project, ignore this warning or
quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in
the CMake cache. If later configuration or build errors occur then this
project may have been written under the assumption that Cygwin is WIN32.
In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead.
(2) If you are developing this project, add the line
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
at the top of your top-level CMakeLists.txt file or set the minimum
required version of CMake to 2.8.4 or higher. Then teach your project to
build on Cygwin without WIN32.
Call Stack (most recent call first):
/usr/share/cmake-2.8.11.2/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
CMakeLists.txt:47 (PROJECT)
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake-2.8.11.2/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/bin/cc" is not able to compile a simple test program.
It fails with the following output:
Change Dir: /。。。/build/CMakeFiles/CMakeTmp
Run Build Command:/。。。/strawberry/c/bin/gmake.exe
"cmTryCompileExec316328232/fast"
。。。/strawberry/c/bin/gmake -f
CMakeFiles/cmTryCompileExec316328232.dir/build.make
CMakeFiles/cmTryCompileExec316328232.dir/build
gmake[1]: Entering directory
`。。。/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report
。。。/build/CMakeFiles/CMakeTmp/CMakeFiles
1
gmake[1]: Leaving directory
`.../CMakeFiles/CMakeTmp'
process_begin: CreateProcess(NULL, /usr/bin/cmake.exe -E
cmake_progress_report
.../build/CMakeFiles/CMakeTmp/CMakeFiles
1, ...) failed.
make (e=2): ?????????????????
gmake[1]: *** [CMakeFiles/cmTryCompileExec316328232.dir/testCCompiler.c.o]
Error 2
gmake: *** [cmTryCompileExec316328232/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:47 (PROJECT)
-- Configuring incomplete, errors occurred!
其實從表現上來講應該是gmake那又問題,我也懷疑是,我把perl在環境變數裡的路徑去掉(我的Path環境變數裡是有一個strawberry的perl路徑)perl的bin目錄下有gmake這個東西,刪掉build檔案夾下的CmakeCache等檔案,同時換32位的cygwin就沒有問題了。在構建例子的時候我就肯定了,就是perl裡的gmake作的怪,把那個路徑從path環境變數裡面刪掉。理論上應該可以考慮在path環境變數中把cygwin的bin目錄放在perl目錄前來屏蔽掉perl路徑的影響,如果遇到這個問題的可以嘗試一下。
在構建例子的時候則遇到這樣的問題:
ndk-build
Android NDK: WARNING:jni/Android.mk:osgNativeLib: non-system libraries in linker flags:
。。。。。。
。。。。。。
Android NDK: This is likely to result in incorrectbuilds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to listthe library dependencies of the
Android NDK: current module
。。。
。。。
。。。oolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:D:/android/osg_android/osges2/obj/local/armeabi/libosg.a(Program.o): infunction std::_Vector_base>::_Vector_impl::_Vector_impl(std::allocatorconst&):C:/android/android-ndk-r9b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_vector.h:87:error: undefined reference to 'std::allocator::allocator(std::allocatorconst&)'
collect2: ldreturned 1 exit status
。。。android-ndk-r9b/build/core/build-binary.mk:577:recipe for target 'obj/local/armeabi/libosgNativeLib.so' failed
make: ***[obj/local/armeabi/libosgNativeLib.so] Error 1
這跟mk檔案中的變數設定方式有關,LOCAL_C_FLAGS這個變數同一行出現了兩個以上的/就會有問題,如果在分行的時候使用空格錯誤就更奇怪了:
$ANDROID_NDK/ndk-build
jni/Android.mk:26: *** 遺漏分隔字元 。 停止。
OK,先寫到這吧,慢慢補充吧。