Android studio编译第3方库libpng ,Box2D (CMake)

编译libpng

下载libpng后,放到目录${ANDROID_NDK}/sources/third_party/libpng
方法1: 引入第3方CMake工程

#Import PNG library

set ( png_src_DIR ${ANDROID_NDK}/sources/third_party/libpng )
set ( png_build_DIR ${ANDROID_NDK}/sources/third_party/libpng/outputs )
file(MAKE_DIRECTORY ${png_build_DIR})

 #Adds the CMakeLists.txt file located in the specified directory  
 #as a build dependency.

add_subdirectory( # Specifies the directory of the CMakeLists.txt file.
                  ${png_src_DIR}
                  # Specifies the directory for the build outputs.
                  ${png_build_DIR} )

 #Adds the output of the additional CMake build as a prebuilt static
 #library and names it lib_png.

add_library( lib_png STATIC IMPORTED )
set_target_properties( lib_png PROPERTIES IMPORTED_LOCATION
                        ${png_build_DIR}/libpng.a 
include_directories( ${png_src_DIR} )

方法2:把代码加入studio 进行编译,修改cmakefile

set ( png_src_DIR ${ANDROID_NDK}/sources/third_party/libpng )
file(GLOB png_SOURCES "${png_src_DIR}/*.c") 
##### #exclude example.c pngtest.c 
list(REMOVE_ITEM png_SOURCES ${png_src_DIR}/example.c ${png_src_DIR}/pngtest.c) 
add_library( # Sets the name of the library. 
             png
             # Sets the library as a shared library.
             STATIC
             # Provides a relative path to your source file(s).
             # Associated headers in the same location as their source
             # file are automatically included.
             ${png_SOURCES})
##### # Specifies a path to native header files. 
include_directories(${png_src_DIR})

编译Box2D

下载box2d后,放到目录${ANDROID_NDK}/sources/third_party/box2d

# Import box2d library 
set ( box2d_src_DIR    
    ${ANDROID_NDK}/sources/third_party/box2d/Box2D ) 
set ( box2d_build_DIR     
    ${ANDROID_NDK}/sources/third_party/box2d/Box2D/outputs ) 
file(MAKE_DIRECTORY ${box2d_build_DIR})
# Adds the CMakeLists.txt file located in the specified directory 
# as a build dependency. 
add_subdirectory( # Specifies the directory of the CMakeLists.txt file.   
                  ${box2d_src_DIR}
                  # Specifies the directory for the build outputs.
                  ${box2d_build_DIR} ) 
# Adds the output of the additional CMake build as a prebuilt static 
# library and names it lib_box2d. 
add_library( lib_box2d STATIC IMPORTED ) 
set_target_properties( lib_box2d PROPERTIES IMPORTED_LOCATION    
                        ${box2d_build_DIR}/Box2D/libBox2D.a)
include_directories( ${box2d_src_DIR} )
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值