用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

相关文章

使用Node.js和PostgreSQL构建数据库应用

《使用Node.js和PostgreSQL构建数据库应用》PostgreSQL是一个功能强大的开源关系型数据库,而Node.js是构建高效网络应用的理想平台,结合这两个技术,我们可以创建出色的数据驱动... 目录初始化项目与安装依赖建立数据库连接执行CRUD操作查询数据插入数据更新数据删除数据完整示例与最佳

Docker多阶段镜像构建与缓存利用性能优化实践指南

《Docker多阶段镜像构建与缓存利用性能优化实践指南》这篇文章将从原理层面深入解析Docker多阶段构建与缓存机制,结合实际项目示例,说明如何有效利用构建缓存,组织镜像层次,最大化提升构建速度并减少... 目录一、技术背景与应用场景二、核心原理深入分析三、关键 dockerfile 解读3.1 Docke

Android实现图片浏览功能的示例详解(附带源码)

《Android实现图片浏览功能的示例详解(附带源码)》在许多应用中,都需要展示图片并支持用户进行浏览,本文主要为大家介绍了如何通过Android实现图片浏览功能,感兴趣的小伙伴可以跟随小编一起学习一... 目录一、项目背景详细介绍二、项目需求详细介绍三、相关技术详细介绍四、实现思路详细介绍五、完整实现代码

在Android中使用WebView在线查看PDF文件的方法示例

《在Android中使用WebView在线查看PDF文件的方法示例》在Android应用开发中,有时我们需要在客户端展示PDF文件,以便用户可以阅读或交互,:本文主要介绍在Android中使用We... 目录简介:1. WebView组件介绍2. 在androidManifest.XML中添加Interne

Three.js构建一个 3D 商品展示空间完整实战项目

《Three.js构建一个3D商品展示空间完整实战项目》Three.js是一个强大的JavaScript库,专用于在Web浏览器中创建3D图形,:本文主要介绍Three.js构建一个3D商品展... 目录引言项目核心技术1. 项目架构与资源组织2. 多模型切换、交互热点绑定3. 移动端适配与帧率优化4. 可

Android协程高级用法大全

《Android协程高级用法大全》这篇文章给大家介绍Android协程高级用法大全,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友跟随小编一起学习吧... 目录1️⃣ 协程作用域(CoroutineScope)与生命周期绑定Activity/Fragment 中手

Python利用PySpark和Kafka实现流处理引擎构建指南

《Python利用PySpark和Kafka实现流处理引擎构建指南》本文将深入解剖基于Python的实时处理黄金组合:Kafka(分布式消息队列)与PySpark(分布式计算引擎)的化学反应,并构建一... 目录引言:数据洪流时代的生存法则第一章 Kafka:数据世界的中央神经系统消息引擎核心设计哲学高吞吐

Springboot项目构建时各种依赖详细介绍与依赖关系说明详解

《Springboot项目构建时各种依赖详细介绍与依赖关系说明详解》SpringBoot通过spring-boot-dependencies统一依赖版本管理,spring-boot-starter-w... 目录一、spring-boot-dependencies1.简介2. 内容概览3.核心内容结构4.

Go语言使用net/http构建一个RESTful API的示例代码

《Go语言使用net/http构建一个RESTfulAPI的示例代码》Go的标准库net/http提供了构建Web服务所需的强大功能,虽然众多第三方框架(如Gin、Echo)已经封装了很多功能,但... 目录引言一、什么是 RESTful API?二、实战目标:用户信息管理 API三、代码实现1. 用户数据

Android 缓存日志Logcat导出与分析最佳实践

《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按