1# Building an NDK Project with Prebuilt Libraries 2 3 4In 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. 5 6 7For example, the prebuilt library **libavcodec_ffmpeg.so** is located in the following directory during development. 8 9 10 11 12 13To 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: 14 15 16``` 17add_library(library SHARED hello.cpp) 18 19add_library(avcodec_ffmpeg SHARED IMPORTED) 20set_target_properties(avcodec_ffmpeg 21 PROPERTIES 22 IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/third_party/FFmpeg/libs/${OHOS_ARCH}/libavcodec_ffmpeg.so) 23 24target_link_libraries(library PUBLIC libace_napi.z.so avcodec_ffmpeg) 25``` 26 27 28When 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. 29 30 31 32 33 34To use the prebuilt library integrated in a remote dependency HAR, write the reference script in the **CMakeLists.txt** file as follows: 35 36 37``` 38set(DEPENDENCY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules) 39add_library(library SHARED IMPORTED) 40set_target_properties(library 41 PROPERTIES 42 IMPORTED_LOCATION ${DEPENDENCY_PATH}/library/libs/${OHOS_ARCH}/liblibrary.so) 43add_library(entry SHARED hello.cpp) 44target_link_libraries(entry PUBLIC libace_napi.z.so library) 45``` 46 47 48To use the prebuilt library integrated in a local HAR, write the reference script in the **CMakeLists.txt** file as follows: 49 50 51``` 52set(LIBRARY_DIR "${NATIVERENDER_ROOT_PATH}/../../../../library/build/default/intermediates/libs/default/${OHOS_ARCH}/") 53add_library(library SHARED IMPORTED) 54set_target_properties(library 55 PROPERTIES 56 IMPORTED_LOCATION ${LIBRARY_DIR}/liblibrary.so) 57add_library(entry SHARED hello.cpp) 58target_link_libraries(entry PUBLIC libace_napi.z.so) 59``` 60