1e41f4b71Sopenharmony_ci 2e41f4b71Sopenharmony_ci# libc++ 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciOpenHarmony uses [libc++](https://libcxx.llvm.org/) of the open-source LLVM project as its C++ runtime library. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci## libc++ Version 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci- Clang/LLVM 15.0.4 from OpenHarmony 4.0 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci- Clang/LLVM 12.0.1 from OpenHarmony 3.2 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci- Clang/LLVM 10.0.1 from OpenHarmony 3.0 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Support for C++ Capabilities 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciThe 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/](https://libcxx.llvm.org/). 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## Selecting libc++ in CMake 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciIn 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: 23e41f4b71Sopenharmony_ci* **c++_shared**: The native library dynamically links **libc++_shared.so**. 24e41f4b71Sopenharmony_ci* **c++_static**: The native library links the static library **libc++_static.a**. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci## C++ Runtime Compatibility 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ciIn OpenHarmony, 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, OpenHarmony differentiates the two libc++ libraries as follows: 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci * System library: uses **libc++.so**, which is released with the system image. 31e41f4b71Sopenharmony_ci * Application native library: uses **libc++_shared.so**, which is released with the application. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciThe 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. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci > **NOTE**<br>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. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci## Precautions 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci- The upgrade of the C++ runtime library toolchain to a major version does not ensure ABI compatibility. If an application package has multiple dynamic libraries, these dynamic libraries must be compiled using the Clang toolchain of the same major version and depend on the libc++_shared library of the same version. Otherwise, unpredictable errors may occur. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci- If there is only one shared library in your application project, you are advised to use **c++_static**, which simplifies the C++ runtime code run by the linker and reduces the package size. Dynamic linking of libc++ is recommended if there are multiple libraries in your project, the dependency is a HAR package of a dynamic library, or there are binary .so packages in the OHPM library. Static linking may cause multiple copies of a function or an object defined in an application, which violates the One Definition Rule of C++. 42