WEB开发网
开发学院手机开发Android 开发 如何移植 library 到 android 阅读

如何移植 library 到 android

 2010-03-26 21:13:00 来源:WEB开发网   
核心提示:最近两天,我在做移植工作,如何移植 library 到 android,可怜,对方给的source code 不完全,最后,我不得不提一下,很多东西要自己去搞定,分享一下移植经验

最近两天,我在做移植工作。可怜,对方给的source code 不完全,很多东西要自己去搞定。

分享一下移植经验,虽然我没有成功。

首先说明一下,Android Bionic C library ,他的设计是尽量简单。

这意味这个C库只围绕着内核提供轻量级的包装,我们让它尽量小,不去处理一些细枝末页的事情。取Bionic这个名字,是因为它由部分BSD和部分linux组成。

就因为这个原因,导致我的移植工作很困难.

我在link时候的错误,事实上在编译的时候就错了,但是我改了头文件,把这些函数声明都加上去了,所以在link的时候报错了:

"undefined reference to 'setmntent'"

"undefined reference to 'endmntent'"

"undefined reference to 'ftime'"

都是因为Bionic C library没有提供实现。要解决这些问题,看来是只能自己加上实现的代码,重新用android toolchain 去编译.

然后,我在说一说Android toolchain,目前最新的toolchain最新是20090323的,android ndk r3(Goto:http://developer.android.com/sdk/ndk/index.html)用的就是这个。这个toolchain是不支持STL的,可以看google group上的讨论,Android程序开发人David turner说:I confirm that the Android framework has been specifically designed to not need any STL / C++ exceptions / RTTI.This was a deliberate decision at the time the platform was first designed, because the available compiler and STL implementations at the time were very

poor and generated humongous code that ran very poorly on the puny ARM CPUs of the time. And all of this has been benchmarked a long time ago and I don't have numbers to share. 总之,说了一堆原因NND不支持STL,取而代之的是ASTL.如果你的代码含有stl,那么恭喜你android toolchain 目前是没办法帮你搞定的。幸运的是,Crystax解决了这个问题(Goto:http://www.crystax.net/android/ndk-r3.php)

即使这样,我仍然发现有问题,我举个简单的例子:

"undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base* ........)'"

std::_Rb_tree_rebalance_for_erase理论上应该在libstdc++.so里有实现,但是很不幸,android的没有。所以,我们只能加上实现,再次重编译stdc++。

最后,我不得不提一下,link要注意顺序ld 库的次序,不然很可能又会error.

Tags:如何 移植 library

编辑录入:coldstar [复制链接] [打 印]
赞助商链接