用NDK构建osg库到Android 平台几点经验

转自 http://blog.csdn.net/giantchen547792075/article/details/17660511

在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内置的

7、参考博文:OSG Android版本编译

                          osg for android学习之一:windows下编译(亲测通过)

这里要感谢两位大神的经验分享。


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<char, std::allocator<char>>::_Vector_impl::_Vector_impl(std::allocator<char>const&):C:/android/android-ndk-r9b/sources/cxx-stl/gnu-libstdc++/4.6/include/bits/stl_vector.h:87:error: undefined reference to 'std::allocator<char>::allocator(std::allocator<char>const&)'

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,先写到这吧,慢慢补充吧。

补充1:

。。。/3.2.0/include/osg/State:1086:67: error: 'glEnableClientState' was not declared in this scope
。。。/3.2.0/include/osg/State:1090:68: error: 'glTexCoordPointer' was not declared in this scope
。。。/3.2.0/include/osg/State: In member function 'void osg::State::disableTexCoordPointer(unsigned int)':
。。。/3.2.0/include/osg/State:1124:46: error: 'GL_TEXTURE_COORD_ARRAY' was not declared in this scope
。。。/3.2.0/include/osg/State:1124:68: error: 'glDisableClientState' was not declared in this scope
。。。/3.2.0/include/osg/State: In member function 'void osg::State::disableTexCoordPointersAboveAndIncluding(unsigned int)':
。。。/3.2.0/include/osg/State:1172:50: error: 'GL_TEXTURE_COORD_ARRAY' was not declared in this scope
。。。/3.2.0/include/osg/State:1172:72: error: 'glDisableClientState' was not declared in this scope
。。。/android/android-ndk-r9b/build/core/build-binary.mk:386: recipe for target 'obj/local/armeabi/objs-debug/osgUtil/UpdateVisitor.o' failed
make[3]: *** [obj/local/armeabi/objs-debug/osgUtil/UpdateVisitor.o] Error 1
make[3]: *** 正在等待未完成的任务....
。。。/android/android-ndk-r9b/build/core/build-binary.mk:386: recipe for target 'obj/local/armeabi/objs-debug/osgUtil/TriStripVisitor.o' failed
make[3]: *** [obj/local/armeabi/objs-debug/osgUtil/TriStripVisitor.o] Error 1
CMakeFiles/ndk.dir/build.make:55: recipe for target 'Android-OpenSceneGraph' failed
make[2]: *** [Android-OpenSceneGraph] Error 2
CMakeFiles/Makefile2:63: recipe for target 'CMakeFiles/ndk.dir/all' failed
make[1]: *** [CMakeFiles/ndk.dir/all] Error 2
Makefile:116: recipe for target 'all' failed
make: *** [all] Error 2

这样的错误话说可以忽略,我试着 重新make了一遍,通过。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值