zoukankan      html  css  js  c++  java
  • android studio CMake NDK:配置笔记

    工具下载:在SDK-Tool中下载CMake, LLDB ,NDK。

    项目创建

     

     配置最后页面的这两项也选上,方便代码调试。

    配置库名称及库的输出路径和格式:

    1.配置CMakeLists.txt

    #设置编译时CMake的最低需求版本
    cmake_minimum_required(VERSION 3.4.1)

    #设置生成的so动态库最后输出的路径
    #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
    add_library(
    #添加的库名
          test-lib
            #库的类型:SHARED表示动态so库,STATIC表示静态a库
          SHARED
    #编译的cpp文件源文件路径
          src/main/cpp/native-lib.cpp)

    #设置NDK本地库里你想使用的库的引用名
    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)

    #设置目标so库生成时,要关联的库
    target_link_libraries( # Specifies the target library.
    test-lib

    # Links the target library to the log library
    # included in the NDK.
    ${log-lib})

    2.配置gradle文件,指定so库CPU框架

    有多个cpp/c文件需要编译的情况处理方式:

    1.指定编译路径下所有的文件

    #对应需要编译cpp的文件路径
    file(GLOB my_srcs "src/main/cpp/*")

    add_library( test-lib  SHARED  ${my_srcs})

    2.将每个cpp文件变为一个库

    add_library( test1-lib  SHARED  native1-lib.cpp)

    add_library(test2-lib   SHARED native2-lib.cpp)

     

     

     
  • 相关阅读:
    解决AD原理图中无法输入中文的问题
    [编程题-京东]小球的距离
    [编程题-京东]上台阶
    [编程题-搜狐]发奖金
    [编程题-搜狐]扎金花
    [leetcode]最长递增序列
    [编程题-搜狐]马戏团
    [编程题-蘑菇街] 投篮游戏
    [编程题-蘑菇街]聊天
    [编程题-蘑菇街]回文串
  • 原文地址:https://www.cnblogs.com/suxiaoqi/p/12457818.html
Copyright © 2011-2022 走看看