• 01-cmake语法-基本


    本系列随笔将结合 OpenCV 的 CMakeLists.txt 来讲解 cmake 的语法。

    这一节,主要介绍一下cmake语法的基本语法。

    cmake语法的基本语法

    # 执行
    cmake . # 表示在当前目录下执行 cmake
    cmake .. # 表示在前一级目录下执行 cmake
    make # 在当前目录下执行 make
    
    
    # 语法
    #1 设置 cmake 版本需求
    cmake_minimum_required(VERSION 2.8)
    
    #2 设置工程名
    project( 工程名 )
    
    #3 生成可执行文件
    add_executable( 可执行文件名 cpp文件 )
    
    #4 生成静态库
    add_library( helloSLAM helloSLAM.cpp )
    
    #5 生成共享库
    add_library( helloSLAMShared SHARED helloSLAM.cpp )
    
    #6 链接可执行文件,xx.o
    target_link_libraries(helloSLAM /home/chan/projects/SLAM/build_lib/libhelloSLAM.a)
    
    #7 设置Debug模式
    set( CMAKE_BUILD_TYPE "Debug" )
    

      

    给出例子:

    1. 文件名“helloSLAM.cpp”,编译的可执行文件名为“helloSLAM”,不指定,默认为“a”。

    Linux 下可执行文件没有后缀名。

    # cmake version requirment
    cmake_minimum_required(VERSION 2.8)
    
    # project name.
    project( helloSLAM )
    
    # generate exectuable file.
    add_executable( helloSLAM helloSLAM.cpp )
    

      

    2. 文件名“helloSLAM.cpp”,编译生成 静态库 ,后缀名“.a”

    # cmake version requirment
    cmake_minimum_required( VERSION 2.8 )
    
    
    # project name.
    project( helloSLAM )
    
    # generate library file.
    add_library( helloSLAM libHelloSLAM.cpp )
    

      

    3. 文件名“helloSLAM.cpp”,编译生成 分享库(不叫动态库) ,后缀名“.a”

    # cmake version requirment
    cmake_minimum_required( VERSION 2.8 )
    
    
    # project name.
    project( helloSLAM )
    
    # generate library file.
    add_library( helloSLAMShared SHARED libHelloSLAM.cpp )
    

      

    4. 加载静态库/分享库,生成可执行文件。

    # cmake version requirment
    cmake_minimum_required(VERSION 2.8)
    
    # project name.
    project( helloSLAM )
    
    # generate exectuable file.
    add_executable( helloSLAM helloSLAM.cpp )
    
    target_link_libraries(helloSLAM /home/chan/projects/SLAM/build_lib/libhelloSLAM.a)
    

      

    本节参考来自高博《视觉SLAM14讲》。

    部分操作,可参考我的github:

    https://github.com/Chenhui2018/SLAM/blob/master/notes/SLAM%E7%AC%94%E8%AE%B01%EF%BC%9A%E6%96%B0%E5%BB%BA%E5%B7%A5%E7%A8%8B%E5%92%8Ccmake.md

  • 相关阅读:
    破解无线网络密码-BT3如何使用1
    翻译记忆软件-塔多思TRADO经典教程_5
    翻译记忆软件-塔多思TRADO经典教程_3
    [Angular] Angular ngSwitch Core Directive In Detail
    [Angular] ngClass conditional
    [Algorithms] Refactor a Linear Search into a Binary Search with JavaScript
    [Algorithms] Divide and Recurse Over an Array with Merge Sort in JavaScript
    [Algorithms] Sort an Array with a Nested for Loop using Insertion Sort in JavaScript
    [Algorithms] Build a Binary Tree in JavaScript and Several Traversal Algorithms
    [Algorithms] Quicksort algorithm using TypeScript
  • 原文地址:https://www.cnblogs.com/alexYuin/p/8874304.html
Copyright © 2020-2023  润新知