dlopen.
Overview
- Create a C/C++ library project
- Cross-compile for HarmonyOS
arm64-v8ausing the NDK - Place the compiled
.sointoentry/libs/arm64-v8a/ - Load and call it from ArkTS via
dlopen
1. Create the External Library
Sourcelibrary.cpp:
extern "C" prevents C++ name mangling, ensuring dlsym("hello") can find the symbol. Without it, the symbol would be mangled to _Z5hellov and dlopen would fail.2. Cross-Compile for HarmonyOS
3. Place the Output
If your project also supports
x86_64 emulator, place the corresponding .so under entry/libs/x86_64/ as well.4. Configure abiFilters
Ensurelibrary/build-profile.json5 contains the target architecture in abiFilters: