android studio开发c++ native程序CMakeLists.txt文件相关修改

主要修改涉及

     添加自定义的*.h文件、*.cpp文件
     添加第三方的*.h文件、*.so文件

1、当前工程已包含native-lib.cpp文件
2、添加自定义的a.h文件、a.cpp文件,与原有native-lib.cpp文件同级目录

add_library(# Sets the name of the library.
			native-lib
			# Sets the library as a shared library.
			SHARED
			# Provides a relative path to your source file(s).
			native-lib.cpp
			a.h
			a.cpp)

3、添加第三方*.so,以添加libopencv.so为例对CMakeLists.txt修改
(1)添加头文件,其中opencv的相关头文件位于C:/include

include_directories(C:/include)

(2)添加库文件,在说明库文件名称时需要省略"lib"前缀和"*.so"后缀,在说明库文件具体路径时不需要省略

add_library(opencv SHARED IMPORTED)
set_target_properties(opencv
					  PROPERTIES 
					  IMPORTED_LOCATION
					  C:/libopencv.so)
					  # 使用${ANDROID_ABI}根据不同的构建平台选择不同文件夹下的库文件
					  # C:/${ANDROID_ABI}/libopencv.so)

如需要查找某一系统库的路径,以查找log库为例,将路径保存在${log-lib}

find_library(# Sets the name of the path variable .
			 log-lib
			 # Specifies the name of the NDK library that you want CMake to locate.
			 log)

(3)链接库文件:自定义库、第三方库、系统库

target_link_libraries(# Specifies the target library.
					  native-lib
					  opencv
					  ${log-lib})

你可能感兴趣的:(android,android,studio,CMakeLists.txt)