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)set_target_properties(avcodec_ffmpeg PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/third_party/FFmpeg/libs/${OHOS_ARCH}/libavcodec_ffmpeg.so) 20 21target_link_libraries(library PUBLIC libace_napi.z.so avcodec_ffmpeg) 22``` 23 24 25When 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. 26 27 28 29 30 31To use the prebuilt library integrated in a remote dependency HAR, write the reference script in the **CMakeLists.txt** file as follows: 32 33 34``` 35set(DEPENDENCY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules) 36add_library(library SHARED IMPORTED) 37set_target_properties(library 38 PROPERTIES 39 IMPORTED_LOCATION ${DEPENDENCY_PATH}/library/libs/${OHOS_ARCH}/liblibrary.so) 40add_library(entry SHARED hello.cpp) 41target_link_libraries(entry PUBLIC libace_napi.z.so library) 42``` 43 44 45To use the prebuilt library integrated in a local HAR, write the reference script in the **CMakeLists.txt** file as follows: 46 47 48``` 49set(LIBRARY_DIR "${NATIVERENDER_ROOT_PATH}/../../../../library/build/default/intermediates/libs/default/${OHOS_ARCH}/") 50add_library(library SHARED IMPORTED) 51set_target_properties(library 52 PROPERTIES 53 IMPORTED_LOCATION ${LIBRARY_DIR}/liblibrary.so) 54add_library(entry SHARED hello.cpp) 55target_link_libraries(entry PUBLIC libace_napi.z.so) 56``` 57