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

2024-05-07 05:38

本文主要是介绍用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了一遍,通过。

这篇关于用NDK构建osg库到Android 平台几点经验的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/966471

相关文章

使用Python构建智能BAT文件生成器的完美解决方案

《使用Python构建智能BAT文件生成器的完美解决方案》这篇文章主要为大家详细介绍了如何使用wxPython构建一个智能的BAT文件生成器,它不仅能够为Python脚本生成启动脚本,还提供了完整的文... 目录引言运行效果图项目背景与需求分析核心需求技术选型核心功能实现1. 数据库设计2. 界面布局设计3

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

深入浅出SpringBoot WebSocket构建实时应用全面指南

《深入浅出SpringBootWebSocket构建实时应用全面指南》WebSocket是一种在单个TCP连接上进行全双工通信的协议,这篇文章主要为大家详细介绍了SpringBoot如何集成WebS... 目录前言为什么需要 WebSocketWebSocket 是什么Spring Boot 如何简化 We

Linux之platform平台设备驱动详解

《Linux之platform平台设备驱动详解》Linux设备驱动模型中,Platform总线作为虚拟总线统一管理无物理总线依赖的嵌入式设备,通过platform_driver和platform_de... 目录platform驱动注册platform设备注册设备树Platform驱动和设备的关系总结在 l

Spring Boot Maven 插件如何构建可执行 JAR 的核心配置

《SpringBootMaven插件如何构建可执行JAR的核心配置》SpringBoot核心Maven插件,用于生成可执行JAR/WAR,内置服务器简化部署,支持热部署、多环境配置及依赖管理... 目录前言一、插件的核心功能与目标1.1 插件的定位1.2 插件的 Goals(目标)1.3 插件定位1.4 核

使用Python构建一个高效的日志处理系统

《使用Python构建一个高效的日志处理系统》这篇文章主要为大家详细讲解了如何使用Python开发一个专业的日志分析工具,能够自动化处理、分析和可视化各类日志文件,大幅提升运维效率,需要的可以了解下... 目录环境准备工具功能概述完整代码实现代码深度解析1. 类设计与初始化2. 日志解析核心逻辑3. 文件处

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

Android ClassLoader加载机制详解

《AndroidClassLoader加载机制详解》Android的ClassLoader负责加载.dex文件,基于双亲委派模型,支持热修复和插件化,需注意类冲突、内存泄漏和兼容性问题,本文给大家介... 目录一、ClassLoader概述1.1 类加载的基本概念1.2 android与Java Class

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Android DataBinding 与 MVVM使用详解

《AndroidDataBinding与MVVM使用详解》本文介绍AndroidDataBinding库,其通过绑定UI组件与数据源实现自动更新,支持双向绑定和逻辑运算,减少模板代码,结合MV... 目录一、DataBinding 核心概念二、配置与基础使用1. 启用 DataBinding 2. 基础布局