Feb 3, 2009

Android STL/STD support

Article by Neil.He
万恶的android在STL和STD的支持上给了C/C++工程师带来了很大的麻烦。
Android的C++支持中只包含少的可怜的std namespace内容(还把std改成的android),和几乎空白的STL(standard Tamplate Library)。
这样的情况造成的严重的后果是,如果你想要porting一个lib到android上,那这个lib最好是连std和stl都不依赖,这对于开发来说无意于一种折磨。
在开发中发现了一点点信息,可能有一定的用处。
如果你的lib依赖stl的一些函数和对象,那么最好是平心静气的找找android的代码里是不是有类似的功能代码,android也是人开发的,也是用C/C++开发的,那么也会遇到类似的问题,所以也会有类似的处理方法,怎么办,缺什么补什么呗。
我在开发中需要用到vector,string,stream等对象,寻寻觅觅,发现还真有,/android/frameworks/base/media/libdrm/mobile2/中有个src/util/ustl-1.0,里面包含了一些stl的支持,虽然简单了点,但是基本上还是够我使用了。
仔细找发现还有很多地方有类似的实现,例如opencore等等。
经过这样看起来是解决了问题,可是android设计大牛们,是否想过这样大家要开发一个lib就要自己实现一部分标准库的功能,那么带来的代码冗余是可想而知的,这样的话,准备一个完整的标准库还是有必要的吧。难道android以后真的强悍到根本不用做中间层的lib,这点我始终怀疑...

7 评论:

卡哩 said...

你好,

有幸在茫茫網海裡面看到你的文章, 關於android對STL的support也是讓我非常頭大, 我現在的工作是要把一個第三方(adobe)的source codes build成android可以用的library(so), 看起來正像你說的那樣, 很多函式android都不支援, 所以無論我build出的so怎麼load都load不到, 應該是跟這個有關吧. 我起初為了避掉linking error (找不到library symbol的error) 於是把 --no-undefined的參數拿掉, 結果雖然so可以build出來, 但是loadlibrary的時候卻fail了. 不知道您對這樣的情況, 能不能提供一些建議給我, 雖然我知道可能要見洞補洞, 但是還希望能給一些方向給我, 好讓我接下來可以走得順一點, 或是一些有用的訊息文章也是可以的, 感謝你

Anonymous said...

Undeniably believe that which you said. Your favorite reason seemed to be on the
net the simplest thing to be aware of. I say to you, I certainly get annoyed while
people consider worries that they plainly don't know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people can take a signal. Will likely be back to get more. Thanks

My web-site ... Diablo III

Anonymous said...

Very rapidly this web site will be famous amid
all blogging visitors, due to it's good articles or reviews

my page - lose weight with HCG

Anonymous said...

Your style is so unique in comparison to other people I have read stuff
from. Thank you for posting when you have the opportunity,
Guess I'll just book mark this blog.

My weblog; i loved this

Anonymous said...

Keep this going please, great job!

Here is my page; http://www.cuteteenporn.net

Anonymous said...

An intriguing discussion is definitely worth comment.

I think that you ought to write more about this subject,
it might not be a taboo matter but generally people don't speak about such issues. To the next! Kind regards!!

Feel free to surf to my web blog; http://www.xxxmoviegalls.com

Anonymous said...

I pay a quick visit every day some blogs and websites to read articles, except this website gives feature based posts.


My blog post ... address e free mail no only porn [secretkiteboarding.com]