阅读《视觉slam十四讲》,留点记录,参考价值不大,自己写着看,为写论文留点素材~
主要参考https://blog.csdn.net/qq_32618327/category_9357175.html?utm_source=ffzl_BWzd 感谢这位博主,写的很详细了。
1.视觉SLAM框架
之后补充
2.linux编程基础(6.28)
在/home下新建一个文件夹Test用来存放测试程序。在/home/Test中新建一个文件helloSLAM.cc,输入如下内容
#include <iostream>
using namespace std;
int main(int argc,char** agrv){
cout<<"hello slam"<<endl;
return 0;
}
1.使用 g++编译
g++ helloSLAM.cc #将helloSLAM.cc编译成可执行文件
生成a.out文件,在终端进入文件夹目录后,输入如下指令运行程序
./a.out #运行程序
2.cmake编译(推荐使用)
在/home/Test中新建CMakeList.txt文件,输入
# 声明要求的 cmake 最低版本
cmake_minimum_required( VERSION 2.8 )
# 声明一个 cmake 工程
project( HelloSLAM )
# 添加一个可执行程序
# 语法:add_executable( 程序名 源代码文件 )
add_executable( helloSLAM helloSLAM.cpp )
为了方便,新建build文件夹用于存放编译生成的中间文件
mkdir build #新建build文件夹
cd build #进入文件夹
cmake .. #编译
make
./helloSLAM #运行程序
3.库的使用
在Test文件夹中新建一个libhelloSLAM.cc文件
#include <iostream>
using namespace std;
void printHello()
{
cout << "Hello SLAM" << endl;
}
在CMakeList.txt中添加
# 添加一个库
add_library( hello libHelloSLAM.cpp )
编译工程(同上2),此时build文件夹中出现一个libhello.a的文件
在 Linux 中,库文件分成两种:
- 静态库,以.a 作为后缀名
- 共享库,以.so 作为后缀名
若要生成共享库,则在CMakeList.txt文件中添加如下命令
# 添加共享库
add_library( hello_shared SHARED libHelloSLAM.cpp )
编译后,在build文件夹中得到libhello_shared.so文件
编写头文件告诉使用者库文件的内容,就可以调用这个库了
在Test文件夹中创建libhelloSLAM.h文件:
#ifndef LIBHELLOSLAM_H_
#define LIBHELLOSLAM_H_
// 上面的宏定义是为了防止重复引用这个头文件而引起的重定义错误
void printHello();
#endif
编写可执行文件usehello.cc,调用printHello()函数
#include "libhelloSLAM.h"
int main( int argc, char** argv )
{
// 使用 libHelloSLAM.h 中的 printHello() 函数
printHello();
return 0;
}
在CMakeList.txt中添加一个可执行程序的生成命令,链接到刚才使用的库上
# 添加一个可执行程序h
add_executable( usehello usehello.cpp )
# 将库文件链接到可执行程序上
target_link_libraries( usehello hello_shared )
hh