用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

相关文章

Android实现两台手机屏幕共享和远程控制功能

《Android实现两台手机屏幕共享和远程控制功能》在远程协助、在线教学、技术支持等多种场景下,实时获得另一部移动设备的屏幕画面,并对其进行操作,具有极高的应用价值,本项目旨在实现两台Android手... 目录一、项目概述二、相关知识2.1 MediaProjection API2.2 Socket 网络

Android实现悬浮按钮功能

《Android实现悬浮按钮功能》在很多场景中,我们希望在应用或系统任意界面上都能看到一个小的“悬浮按钮”(FloatingButton),用来快速启动工具、展示未读信息或快捷操作,所以本文给大家介绍... 目录一、项目概述二、相关技术知识三、实现思路四、整合代码4.1 Java 代码(MainActivi

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

使用Python构建一个Hexo博客发布工具

《使用Python构建一个Hexo博客发布工具》虽然Hexo的命令行工具非常强大,但对于日常的博客撰写和发布过程,我总觉得缺少一个直观的图形界面来简化操作,下面我们就来看看如何使用Python构建一个... 目录引言Hexo博客系统简介设计需求技术选择代码实现主框架界面设计核心功能实现1. 发布文章2. 加

深入理解Apache Kafka(分布式流处理平台)

《深入理解ApacheKafka(分布式流处理平台)》ApacheKafka作为现代分布式系统中的核心中间件,为构建高吞吐量、低延迟的数据管道提供了强大支持,本文将深入探讨Kafka的核心概念、架构... 目录引言一、Apache Kafka概述1.1 什么是Kafka?1.2 Kafka的核心概念二、Ka

Android实现打开本地pdf文件的两种方式

《Android实现打开本地pdf文件的两种方式》在现代应用中,PDF格式因其跨平台、稳定性好、展示内容一致等特点,在Android平台上,如何高效地打开本地PDF文件,不仅关系到用户体验,也直接影响... 目录一、项目概述二、相关知识2.1 PDF文件基本概述2.2 android 文件访问与存储权限2.

Android Studio 配置国内镜像源的实现步骤

《AndroidStudio配置国内镜像源的实现步骤》本文主要介绍了AndroidStudio配置国内镜像源的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、修改 hosts,解决 SDK 下载失败的问题二、修改 gradle 地址,解决 gradle

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(