android CMakeLists

本文详细介绍了如何使用CMake配置Android项目的构建环境,包括设置CMake最低版本需求,定义并链接共享库,如samba_client,以及如何在项目中包含预编译的库。同时,文章还展示了如何通过find_library和target_link_libraries指令来查找和链接系统库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://developer.android.google.cn/studio/projects/configure-cmake

https://blog.youkuaiyun.com/songmingzhan/article/details/80720903

 

# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.

add_library(samba_client
            SHARED
            src/main/cpp/jni_helper/JniHelper.cc
            src/main/cpp/jni_helper/JavaClassCache.cc
            src/main/cpp/samba_client/SambaClient.cc
            src/main/cpp/credential_cache/CredentialCache.cc
            )

include_directories(src/main/cpp)

set(CMAKE_CXX_FLAGS
    "${CMAKE_CXX_FLAGS} -std=c++0x -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-all -fPIE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pie")

# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

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 )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

#set(libfolder "${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}")
set(libfolder "${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}")
add_library(libsmbclient
            SHARED
            IMPORTED)
set_target_properties(libsmbclient
                      PROPERTIES IMPORTED_LOCATION
                      ${libfolder}/libsmbclient.so)

target_link_libraries(samba_client ${log-lib} libsmbclient)

 

转载于:https://www.cnblogs.com/pengmn/p/10373156.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值