NDK: could not load needed library 'libstlport_shared.so' for 'libxxxxx'
来源:互联网 发布:中外政治制度专业 知乎 编辑:程序博客网 时间:2024/05/13 23:58
C++ Library Support
On this page
- Helper Runtimes
- Runtime Characteristics
- Important Considerations
- Licensing
The Android platform provides a very minimal C++ runtime support library (libstdc++
). This minimal support does not include, for example:
- Standard C++ Library support (except a few trivial headers).
- C++ exceptions support
- RTTI support
The NDK provides headers for use with this default library. In addition, the NDK provides a number of helper runtimes that provide additional features. This page provides information about these helper runtimes, their characteristics, and how to use them.
Helper Runtimes
Table 1 provides names, brief explanations, and features of runtimes available inthe NDK.
libstdc++
(default)The default minimal system C++ runtime library.N/Agabi++_static
The GAbi++ runtime (static).C++ Exceptions and RTTIgabi++_shared
The GAbi++ runtime (shared).C++ Exceptions and RTTIstlport_static
The STLport runtime (static).C++ Exceptions and RTTI; Standard Librarystlport_shared
The STLport runtime (shared).C++ Exceptions and RTTI; Standard Librarygnustl_static
The GNU STL (static).C++ Exceptions and RTTI; Standard Librarygnustl_shared
The GNU STL (shared).C++ Exceptions and RTTI; Standard Libraryc++_static
The LLVM libc++ runtime (static).C++ Exceptions and RTTI; Standard Libraryc++_shared
The LLVM libc++ runtime (shared).C++ Exceptions and RTTI; Standard LibraryHow to set your runtime
Use the APP_STL
variable in your Application.mk
file to specify the runtime you wish to use. Use the values in the "Name" column in Table 1 as your setting. For example:
APP_STL := gnustl_static
You may only select one runtime for your app, and can only do in Application.mk
.
Even if you do not use the NDK build system, you can still use STLport, libc++ or GNU STL. For more information on how to use these runtimes with your own toolchain, see Standalone Toolchain.
Runtime Characteristics
libstdc++ (default system runtime)
This runtime only provides the following headers, with no support beyond them:
cassert
cctype
cerrno
cfloat
climits
cmath
csetjmp
csignal
cstddef
cstdint
cstdio
cstdlib
cstring
ctime
cwchar
new
stl_pair.h
typeinfo
utility
GAbi++ runtime
This runtime provides the same headers as the default runtime, but adds support for RTTI (RunTime Type Information) and exception handling.
STLport runtime
This runtime is an Android port of STLport (http://www.stlport.org). It provides a complete set of C++ standard library headers. It also, by embedding its own instance of GAbi++, provides support for RTTI and exception handling.
While shared and static versions of this runtime are avilable, we recommend using the shared version. For more information, see Static runtimes.
The shared library file is named libstlport_shared.so
instead of libstdc++.so
as is common on other platforms.
In addition to the static- and shared-library options, you can also force the NDK to build the library from sources by adding the following line to your Application.mk
file, or setting it in your environment prior to building:
STLPORT_FORCE_REBUILD := true
GNU STL runtime
This runtime is the GNU Standard C++ Library, (libstdc++-v3
). Its shared library file is namedlibgnustl_shared.so
.
libc++ runtime:
This runtime is an Android port of LLVM libc++. Its shared library file is named libc++_shared.so
.
By default, this runtime compiles with -std=c++11
. As with GNU libstdc++
, you need to explicitly turn on exceptions or RTTI support. For information on how to do this, see C++ Exceptions and RTTI.
The NDK provides prebuilt static and shared libraries for libc++
, but you can force the NDK to rebuild libc++
from sources by adding the following line to your Application.mk
file, or setting it in your environment prior to building:
LIBCXX_FORCE_REBUILD := true
Atomic support
If you include <atomic>
, it's likely that you also need libatomic
. If you are using ndk-build
, add the following line:
LOCAL_LDLIBS += -latomic
If you are using your own toolchain, use:
-latomic
Compatibility
The NDK's libc++ is not stable. Not all the tests pass, and the test suite is not comprehensive. Some known issues are:
- Using
c++_shared
on ARM can crash when an exception is thrown. - Support for
wchar_t
and the locale APIs is limited.
You should also make sure to check the "Known Issues" section of the changelog for the NDK release you are using.
Warning: Attempting to change to an unsupported locale will not fail. The operation will succeed, but the locale will not change and the following message will appear in logcat
.
newlocale() WARNING: Trying to set locale to en_US.UTF-8 other than "", "C" or "POSIX"
Important Considerations
C++ Exceptions
In all versions of the NDK later than NDKr5, the NDK toolchain allows you to use C++ runtimes that support exception handling. However, to ensure compatibility with earlier releases, it compiles all C++ sources with -fno-exceptions
support by default. You can enable C++ exceptions either for your entire app, or for individual modules.
To enable exception-handling support for your entire app, add the following line to your Application.mk
file. To enable exception-handling support for individual modules', add the following line to their respective Android.mk
files.
APP_CPPFLAGS += -fexceptions
RTTI
In all versions of the NDK later than NDKr5, the NDK toolchain allows you to use C++ runtimes that support RTTI. However, to ensure compatibility with earlier releases, it compiles all C++ sources with -fno-rtti
by default.
To enable RTTI support for your entire app for your entire application, add the following line to yourApplication.mk
file:
APP_CPPFLAGS += -frttiTo enable RTTI support for individual modules, add the following line to their respective
Android.mk
files:LOCAL_CPP_FEATURES += rttiAlternatively, you can use:
LOCAL_CPPFLAGS += -frtti
Static runtimes
Linking the static library variant of a C++ runtime to more than one binary may result in unexpected behavior. For example, you may experience:
- Memory allocated in one library, and freed in the other, causing memory leakage or heap corruption.
- Exceptions raised in
libfoo.so
going uncaught inlibbar.so
, causing your app to crash. - Buffering of
std::cout
not working properly
In addition, if you link two shared libraries–or a shared library and an executable– against the same static runtime, the final binary image of each shared library includes a copy of the runtime's code. Having multiple instances of runtime code is problematic because of duplication of certain global variables that the runtime uses or provides internally.
This problem does not apply to a project comprising a single shared library. For example, you can link againststlport_static
, and expect your app to behave correctly. If your project requires several shared library modules, we recommend that you use the shared library variant of your C++ runtime.
Shared runtimes
If your app targets a version of Android earlier than Android 4.3 (Android API level 18), and you use the shared library variant of a given C++ runtime, you must load the shared library before any other library that depends on it.
For example, an app may have the following modules:
- libfoo.so
- libbar.so which is used by libfoo.so
- libstlport_shared.so, used by both libfoo and libbar
You must load the libraries in reverse dependency order:
static { System.loadLibrary("stlport_shared"); System.loadLibrary("bar"); System.loadLibrary("foo"); }
Note: Do not use the lib
prefix when calling System.loadLibrary()
.
Licensing
STLport is licensed under a BSD-style open-source license. See $NDK/sources/cxx-stl/stlport/README
for more details about STLport.
GNU libstdc++ is covered by the GPLv3 license, and not the LGPLv2 or LGPLv3. For more information, see Licenseon the GCC website.
LLVM libc++
is dual-licensed under both the University of Illinois "BSD-Like" license and the MIT license.
- NDK: could not load needed library 'libstlport_shared.so' for 'libxxxxx'
- 集成环信运行提示UnsatisfiedLinkError: dlopen failed: could not load library "libhyphenate_av.so" needed by "
- could not load library libopencv_java.so
- java.lang.UnsatisfiedLinkError: could not load needed library 'library' : link_image[1963]:
- 探索之安卓调用GO生成的动态链接库"failed: dlopen failed: could not load library "libpthread.so.0" needed by ***"的了解
- 解决利用NDK开发android版本的opencv应用dlopen failed: could not load library libopencv_java.so
- NDK library "libgnustl_shared.so" not found
- Could not find lua. Lua is needed for some interfaces
- 解决android studio can not load library from so file
- xcode : could not load inserted library: /usr/lib/libgmalloc.dylib
- dyld: could not load inserted library: /usr/lib/libgmalloc.dylib
- dyld: could not load inserted library: /usr/lib/libgmalloc.dylib
- dyld: could not load inserted library: /usr/lib/libgmalloc.dylib
- Xcode报错信息dyld: could not load inserted library
- java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons解决方法
- dlopen failed: could not load library 的问题
- 使用Indy解决Could not load SSL Library错误
- xcode : could not load inserted library: /usr/lib/libgmalloc.dylib
- 银行信息技术类笔试题(面试)-浅析
- POJ 1321 棋盘问题
- LeetCode|Rectangle Area
- Redis运行流程源码解析
- CodeForces 666A Reberland Linguistics(DP)
- NDK: could not load needed library 'libstlport_shared.so' for 'libxxxxx'
- C - Defuse the Bomb
- hdu2925 Musical Chairs && poj3517 And Then There Was One(约瑟夫环)
- Mac的mysql出现Table 'AAA' is marked as crashed and should be repaired
- POJ 3279Fliptile
- stm32中断学习篇(1)——以定时器为例
- apche2.2安装
- Enumeration接口和Iterator接口的区别
- TCP UDP STCP的端口是独立的