1e41f4b71Sopenharmony_ci# Building an NDK Project with Prebuilt Libraries 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ciIn an NDK project, you can use the CMake syntax to import and use prebuilt libraries. When prebuilt libraries are referenced, the prebuilt libraries in the **libs** directory of the module and the prebuilt libraries declared in the **CMakeList.txt** script are packaged. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciFor example, the prebuilt library **libavcodec_ffmpeg.so** is located in the following directory during development. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciTo use it in your project, add it through **add_library** in the **CMakeLists.txt** script of the module and declare information such as the path to the prebuilt library. Then you can declare the link to the prebuilt library in **target_link_libraries**. The following is an example of the script: 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci``` 17e41f4b71Sopenharmony_ciadd_library(library SHARED hello.cpp) 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciadd_library(avcodec_ffmpeg SHARED IMPORTED) 20e41f4b71Sopenharmony_ciset_target_properties(avcodec_ffmpeg 21e41f4b71Sopenharmony_ci PROPERTIES 22e41f4b71Sopenharmony_ci IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/third_party/FFmpeg/libs/${OHOS_ARCH}/libavcodec_ffmpeg.so) 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_citarget_link_libraries(library PUBLIC libace_napi.z.so avcodec_ffmpeg) 25e41f4b71Sopenharmony_ci``` 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ciWhen prebuilt libraries are used in the HAR, the currently built libraries and prebuilt libraries required for linking are packed to the **libs** directory in the HAR, as shown in the following figure. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ciTo use the prebuilt library integrated in a remote dependency HAR, write the reference script in the **CMakeLists.txt** file as follows: 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci``` 38e41f4b71Sopenharmony_ciset(DEPENDENCY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules) 39e41f4b71Sopenharmony_ciadd_library(library SHARED IMPORTED) 40e41f4b71Sopenharmony_ciset_target_properties(library 41e41f4b71Sopenharmony_ci PROPERTIES 42e41f4b71Sopenharmony_ci IMPORTED_LOCATION ${DEPENDENCY_PATH}/library/libs/${OHOS_ARCH}/liblibrary.so) 43e41f4b71Sopenharmony_ciadd_library(entry SHARED hello.cpp) 44e41f4b71Sopenharmony_citarget_link_libraries(entry PUBLIC libace_napi.z.so library) 45e41f4b71Sopenharmony_ci``` 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciTo use the prebuilt library integrated in a local HAR, write the reference script in the **CMakeLists.txt** file as follows: 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci``` 52e41f4b71Sopenharmony_ciset(LIBRARY_DIR "${NATIVERENDER_ROOT_PATH}/../../../../library/build/default/intermediates/libs/default/${OHOS_ARCH}/") 53e41f4b71Sopenharmony_ciadd_library(library SHARED IMPORTED) 54e41f4b71Sopenharmony_ciset_target_properties(library 55e41f4b71Sopenharmony_ci PROPERTIES 56e41f4b71Sopenharmony_ci IMPORTED_LOCATION ${LIBRARY_DIR}/liblibrary.so) 57e41f4b71Sopenharmony_ciadd_library(entry SHARED hello.cpp) 58e41f4b71Sopenharmony_citarget_link_libraries(entry PUBLIC libace_napi.z.so) 59e41f4b71Sopenharmony_ci``` 60