目录

libc++

HarmonyOS uses libc++ of the open-source LLVM project as its C++ runtime library.

libc++ Version

Support for C++ Capabilities

The C++11 and C++14 standards are supported, and the C++17 and C++20 standards are on the way. For details about the standards supported, see the corresponding Release Notes at https://libcxx.llvm.org/.

Selecting libc++ in CMake

In the {ndk_root}/build/cmake/ohos.toolchain.cmake file of the NDK, the OHOS_STL variable specifies the mode, in which the native library links the C++ runtime library. The OHOS_STL can be set to any of the following values:

C++ Runtime Compatibility

In HarmonyOS, both the system library and the application native library use libc++. However, the upgrade pace of the two libraries is different, and the dependent C++ runtime versions may be different. The libc++ of the system library is updated with the image version, while the libc++ of the application native library is updated with the version of the SDK used for compilation. The two libc++ libraries may be different from multiple major versions, which causes Application Binary Interface (ABI) compatibility issues. To solve this problem, HarmonyOS differentiates the two libc++ libraries as follows:

* System library: uses **libc++.so**, which is released with the system image.
* Application native library: uses **libc++_shared.so**, which is released with the application.

The two libc++ libraries use different namespaces. libc++_shared.so uses __n1 as the namespace for C++ symbols, and libc++.so uses __h for C++ symbols.

The system library cannot use the libc++ of the application native library, and vice versa. Currently, the Native APIs must be C interfaces only. This also isolates the two libc runtime environments.

Precautions