博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android NDK 对于c++的支持(mk文件内编译选项)
阅读量:6360 次
发布时间:2019-06-23

本文共 4919 字,大约阅读时间需要 16 分钟。

hot3.png

一   Android ndk  支持c ++标准库文档,阉割很多c++  stl特性
C++ support with the Android NDK
================================
The Android platform provides a very minimal C++ runtime support library
(/system/lib/libstdc++) and corresponding headers for it in the NDK.
I. C++ Exceptions support:
--------------------------
The NDK toolchain supports C++ exceptions, since NDK r5, however all C++
sources are compiled with -fno-exceptions support by default, for
compatibility reasons with previous releases.
To enable it, use the '-fexceptions' C++ compiler flag. This can be done
by adding the following to every module definition in your Android.mk:
    LOCAL_CPPFLAGS += -fexceptions
More simply, add a single line to your Application.mk, the setting will
automatically apply to all your project's NDK modules:
    APP_CPPFLAGS += -fexceptions
NOTE: The obsolete "arm-eabi-4.4.0" toolchain provided for backwards
      compatibility with this NDK does not support exceptions!
II. RTTI support:
------------------
Similarly, the NDK toolchain supports C++ RTTI (RunTime Type Information)
since NDK r5, but all C++ sources are built with -fno-rtti by default for
compatibility reasons. To enable it, add the following to your module
declarations:
    LOCAL_CPPFLAGS += -frtti
Or more simply to your Application.mk:
    APP_CPPFLAGS += -frtti
NOTE: The obsolete "arm-eabi-4.4.0" toolchain provided for backwards
      compatibility with this NDK does not support RTTI!
III. Selecting the C++ Standard Library Implementation:
-------------------------------------------------------
By default, the headers and libraries for the minimal C++ runtime system
library (/system/lib/libstdc++.so) are used when building C++ sources.
You can however select a different implementation by setting the variable
APP_STL to something else in your Application.mk, for example:
  APP_STL := stlport_static
To select the static STLport implementation provided with this NDK.
Value APP_STL values are the following:
   system              -> Use the default minimal C++ runtime library.
   stlport_static      -> Use STLport built as a static library.
   stlport_shared      -> Use STLport built as a shared library.
WARNING: IMPORTANT CAVEAT
     AT THE MOMENT, OUR STLPORT IMPLEMENTATION DOES NOT SUPPORT EXCEPTIONS
     AND RTTI. PLEASE BE SURE TO NOT USE -fexceptions OR -frtti IN ALL
     MODULES THAT USE IT.
WARNING: END OF IMPORTANT CAVEAT
  "stlport_shared" is preferred if you have several shared libraries in your
  project that use the C++ STL, because it avoids duplication of functions
  and more importantly of global variables (e.g. std::cout) in each one of
  them, which can have surprising results.
  On the other hand, you will have to load it explicitely when starting your
  application, as in the following example:
     static {
         System.loadLibrary("stlport_shared");
         System.loadLibrary("foo");
         System.loadLibrary("bar");
     }
  Where both "libfoo.so" and "libbar.so" depend on "libstlport_shared.so".
  Note that the shared library's name if "libstlport_shared.so" to avoid
  naming conflicts with certain Android system images which include a
  system-level libstlport.so (which happens to not be ABI-stable and
  cannot be used from NDK-generated machine code).
  "stlport_static" is preferred if you have only one shared library in your
  project: only the STL functions and variables you actually need will be
  linked to your machine code, reducing its code size, and you won't need
  to load the dynamic stlport_shared at startup.
IV. STLport-specific issues:
----------------------------
This NDK provides prebuilt static and shared libraries for STLport,
but you can force it to be rebuilt from sources by defining the following
in your environment or your Application.mk before building:
    STLPORT_FORCE_REBUILD := true
STLport is licensed under a BSD-style open-source license. See
sources/cxx-stl/stlport/README for more details about the library.
V. Future Plans:
----------------
  - Make STLport compatible with C++ exceptions and RTTI
  - Full GNU libstdc++ support
  - uSTL support?
二 : 第三方 c++  stl  for  ndk  ;使ndk完全支持c++ 模板块特性
NDK r5 add a lot of useful features
but without C++ exceptions or RTTI,
I still prefer CrystaX r4 version for my code.
Any plan to improve NDK r5 ? Thanks
I would like to second that. While r5 does support C++ exceptions, they don't actually work on API level 3 (Android 1.5), while the crystax r4 version works there. So crystax r5 would make sense.
Yes, r5 version of crystax NDK will be released soon. It will contain many improvements such as wcharsupport and more smooth C++ support.
First (experimental) build with enabled wchar_t support is uploaded to. This archive contains both Windows and Linux binaries so can be used on both platforms; Darwin binaries are not ready yet. I don't publish it on main page because it's not ready to release yet; however, many peoples could start use it and report issues.

New build uploaded with many bug fixes included:

转载于:https://my.oschina.net/zhuzihasablog/blog/98277

你可能感兴趣的文章
Linux服务器部署系列之八—Sendmail篇
查看>>
端口扫描 1
查看>>
os.path官方文档(附翻译)
查看>>
延迟添加队列
查看>>
javascript学习(1)——[基础回顾]变量、声明、数据类型、类型转换
查看>>
javascript学习(6)——[基础回顾]继承/聚合
查看>>
身份证号码的正则校验+升级版
查看>>
【C++ STL 优先队列priority_queue】
查看>>
js.面向对象
查看>>
ajax分页实现,jquery.pagination.js
查看>>
第八次作业—— 缺陷管理(含缺陷管理工具的配置实验)
查看>>
15 个 Android 通用流行框架大全
查看>>
通过点击LI,显示对应的DIV并隐藏其他DIV
查看>>
FeiQ项目
查看>>
跟随我在oracle学习php(19)
查看>>
怎么在Ubuntu上替换ESC键
查看>>
Java定时任务Timer、TimerTask与ScheduledThreadPoolExecutor详解
查看>>
5.Appium 安卓自动化(UIAutomator)
查看>>
[ISSUE]Lambda binding for lua is not supported.
查看>>
222
查看>>