C/C++系列
编译单个.cpp文件
方法一:
g++ test.cpp //生成a.out可执行文件
g++ -o test.out test.cpp //生成test.out可执行文件
方法二:
g++ -c test.cpp -o test.o //生成test.o可执行文件g++
g++ -o test.out test.o //将test.o链接成可执行文件test.cpp
编译多个.cpp和.h文件(即使用库)
静态库:以.a为后缀名,每次调用都会生成一个副本
共享库:以.so为后缀名,只有一个副本
常用方法:使用cmake工具自动生成makefile文件
新建CMakeLists.txt文件,写入以下代码
project(usehello) //声明一个cmake工程
add_library(hello libhello.cpp) //将libhello.cpp文件编译成一个hello的静态库
add_library(hello SHARED libhello.cpp) //与上一个作用一样,生成共享库
add_executable(usehello usehello.cpp) //由主cpp文件生成可执行文件usehello
target_link_libraries(usehello hello) //将生成的库链接到可执行文件
编写完成后,先执行
cmake . //对当前目录进行分析,生成makefile文件
make //进行编译
---------------------------------------------------------------------
为了让cmake生成的中间文件不随便存在,常使用以下命令
mkdir build //建立一个中间文件夹
cd build
cmake .. //..表示对上一层文件进行分析
make //进行编译
-----------------------------------------------------------------------
int main(int argc, char *argv[])中
argc是命令行总的参数个数
argv[]是argc个参数,其中argv[0]指向输入的程序路径及名称,以后为参数
Ubuntu常见命令
top //查看cpu占用率
tar -xvf file.tar //解压 tar包
tar -xzvf file.tar.gz //解压tar.gz
tar -xjvf file.tar.bz2 //解压 tar.bz2
tar -xZvf file.tar.Z //解压tar.Z
unrar e file.rar //解压rar
unzip file.zip //解压zip
Ros常见命令
固定频率重复发布话题
rostopic pub -r 10 /话题名 /消息类型