• SLAM程序Linux版第一节


    创建填加程序内容main.cpp

     gedit main.cpp
    
    • 1

    填加的内容

    #include //头文件
    
    using namespace std;
    
    int main()//主函数
    
    {
    
        cout << "Hello SLAM!\n";//cout是输出,\n是换行符,“”中可输入中文
    
        return 0;//结束程序
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    编译main.cpp程序

    g++ main.cpp
    
    • 1

    文件里面多了一个a.out文件

    linux上输入,会出现Hello SLAM!

    ./a.out 
    
    • 1
     g++ main.cpp -o halloslam
     ./halloslam 
    
    • 1
    • 2
    输出:Hello SLAM!
    
    • 1

    cmake方式

    先下载 cmake

     sudo apt install cmake
    sudo apt-get install g++
    which cmake
    
    • 1
    • 2
    • 3

    显示有地址着完成安装

    先编写CMakeLists.txt文件

    gedit CMakeLists.txt
    
    • 1

    写入内容

    cmake_minimum_required(VERSION 2.8)
    
    project(halloslam)
    
    add_executable(halloslam main.cpp)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    进行编译
    cmake .
    make
    
    • 1
    • 2
    下面生产的文件
    a.out           CMakeFiles           CMakeLists.txt  main.cpp
    CMakeCache.txt  cmake_install.cmake  halloslam       Makefile
    
    • 1
    • 2
    把主文件内容删除,使用build文件
    rm -rf CMakeCache.txt  CMakeFiles cmake_install.cmake Makefile
    
    • 1

    创建build文件进行编译

     mkdir build
    cd duild
    cmake  ..
    make
    
    • 1
    • 2
    • 3
    • 4
    cd到主文件中创建一个 hello.cpp文件
    gedit hello.cpp
    
    • 1
    写入的文件程序
    #include 
    using namespace std;
    void printhello(){
    	cout<<"hello slam"<<endl;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在主文件 CMakeLists.txt中添加程序

    CMakeLists.txt
    add_library(hello hello.cpp)
    
    • 1
    在主文件hello.h程序
    创建hello.h:gedit hello.h
    #pragma once
    void printHello();
    
    • 1
    • 2

    进入build文件中在进行编译

    cmake  ..
    make
    
    • 1
    • 2
    新增加了:libhello.a文件,对之前的函数进行打了个包,有了找个就你能调用hello的这个函数
    cd …到主文件中,在创建一个useHello.pp文件添加hello.h头文件
    gedit useHello.cpp
    
    
    • 1
    • 2
    文件内容
    #include "hello.h"
    int main()
    {
    	printHello();
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    useHello.cpp和hello.h形成了完整的库,就能调用useHello.cpp实现

    再添加 gedit CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    
    project(halloslam)
    
    add_executable(halloslam main.cpp)
    
    add_library(hello hello.cpp)
    
    
    add_executable(useHello useHello.cpp)
    
    target_link_libraries(useHello hello)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
  • 相关阅读:
    QT添加菜单栏-工具栏-中心区域-状态栏-dock 示范
    heapq制作优先级队列
    [项目管理-8]:软硬件项目管理 - 项目成本管理(钱、财)
    Python基础分享之缩进和选择
    数字IC必学之《Skill入门教程》
    J9数字论:一文看懂私有链与联盟链
    Python面向对象编程
    msys2安装mingw开发环境
    学习常用算法——python
    QT:使用行编辑器、滑动条、滚动条、进度条、定时器
  • 原文地址:https://blog.csdn.net/qq_46107892/article/details/126782108