【Linux】CMake编译C/C++工程文件

2023-05-16

【Linux】CMake编译C/C++工程文件


文章目录

  • 【Linux】CMake编译C/C++工程文件
  • 前言
  • 一、CMake编译工程
    • 1.1 两种方式设置编译规则
    • 1.2 两种构建方式
    • 1.3 CMake构建C/C++工程流程
  • 二、CMake重要指令及常用变量
    • 2.1 CMake语法特性
    • 2.2 CMake重要指令
    • 2.3 CMake常用变量
    • 2.4 生成静态库/共享库
      • 2.4.1生成静态库
      • 2.4.2 生成共享库
  • 三、使用案例
    • 3.1 单文件直接编译(内部构建)
    • 3.2 多目录工程直接编译(外部构建)
    • 3.3 多目录工程生成库编译(外部构建)
  • 总结
  • 参考资料


前言

CMake 是一个开源、跨平台的管理源代码构建的工具。CMake 广泛用于 C 和 C++ 语言,但它也可以用于构建其他语言的源代码。makefile通常依赖于你当前的编译平台,使用CMake 可以产生自动化生成makefile,达到可以移植跨平台的目的。

一、CMake编译工程

项目主目录存在一个CMakeLists.txt文件

1.1 两种方式设置编译规则

  • 包含源文件的子文件夹包含CMakeLists.txt文件,主目录的CMakeLists.txt通过add_subdirectory添加子目录即可
  • 包含源文件的子文件夹未包含CMakeLists.txt文件,子目录编译规则体现在主目录的CMakeLists.txt中

1.2 两种构建方式

  • 内部构建(in-source build):内部构建会在同级目录下产生一大堆中间文件,与源文件放在一起显得杂乱无章
  • 外部构建(out-of-source build):将编译输出文件与源文件放在不同目录中,常创建一个build目录,将编译输出文件放在build目录下

1.3 CMake构建C/C++工程流程

  • 手动编写CMakeLists.txt
  • 执行cmake PATH生成Makefile(PATH是顶层CMakeLists.txt所在的目录)
  • 执行命令make进行编译

二、CMake重要指令及常用变量

2.1 CMake语法特性

  • 基本语法格式:指令(参数1 参数二…)
  • 参数使用括号括起来
  • 指令名不区分大小写,参数或变量区分大小写
  • 指令名不区分大小写无关,参数和变量区分大小写

2.2 CMake重要指令

  • cmake_minimum_required:指定CMake最小版本要求
    语法:cmake_minimum_required(VERSION versionnumber [FATAL_ERROR])

    #设置CMake最低版本为2.5
    cmake_minimum_required(VERSION 2.5)
    
  • project:定义工程名称,并且可指定工程支持的语言
    语法:project(projectname [CXX] [C] [Java])

    #设置工程名为HELLO
    project(HELLO)
    
  • set:显示定义变量
    语法:set(VAR [VALUE] [CACHE TYPE DOCSTRING [FORCE]]))

    #定义变量MYFRIEND_SRC,其值为include/myfriend.h src/myfriend.cpp
    set(MYFRIEND_SRC include/myfriend.h src/myfriend.cpp)
    
  • include_directories:向工程添加多个特定的头文件搜索路径
    语法:include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 …)

    #将目录/usr/include/myincludefolder ./include添加进头文件搜索路径
    include_directories(/usr/include/myincludefolder ./include)
    
  • link_directories:向工程添加多个特定库文件的搜索路径
    语法:link_directories(dir1 dir2 …)

    #将目录/usr/lib/mylibfolder ./lib添加进库文件搜索路径
    link_directories(/usr/lib/mylibfolder ./lib)
    
  • add_library:生成库文件
    语法:add_library(libname [SHARED|STATIC|MODULE] [EXCLUDE_FROM_ALL] source1 source2 … sourceN)

    #通过变量SRC生成libhello.so共享库
    add_library(hello SHARED ${SRC})
    
  • add_compile_options:添加编译参数
    语法:add_compile_options(option1 option2 …)

    #添加编译参数-g -o2 -std=c++11(相当于g++ -g -o2 -std=c++11add_compile_options(-g -o2 -std=c++11)
    
  • add_executable:生成可执行文件
    语法:add_executable(exename souce1 source2 …)

    #生成可执行文件main_cmake,源文件为main.cpp、src/myfriend.cpp
    #相当于 g++ main.cpp src/myfriend.cpp -Iinclude -o main
    add_executable(main_cmake main.cpp src/myfriend.cpp)
    
  • target_link_libraries:为target添加需要链接的共享库(相当于g++编译时的-I参数)
    语法:target_link_libraries(target library<debug| optimized> library2…)

    #将MYFRINED_SHARED动态库文件链接到可执行文件main_cmake
    target_link_libraries(main_cmake MYFRINED_SHARED)
    
  • add_subdirectories:向当前工程添加存放源文件的子目录,并且可以指定中间二进制和目标二进制文件的存放位置
    语法:add_subdirectories(source_dir [binary_dir] [EXCLUDE_FROM_ALL])

    #添加src子目录,src需要有一个CMakeLists.txt文件
    add_subdirectories(src)
    
  • aux_source_directory:发现一个目录下所有的源代码文件并将列表存储在一个变量中,这个指令临时被用来构建源文件列表
    语法:aux_source_directory(dir VARIABLE)

    #定义SRC变量,其值为当前目录(.)下所有的源代码文件
    aux_source_directory(. SRC)
    #编译SRC变量所代表的所有源代码文件,生成main可执行文件
    add_executable(main ${SRC})
    

2.3 CMake常用变量

  • CMAKE_C_FLAGS:gcc编译选项
  • CMAKE_CXX_FLAGS:g++编译选项
  • CMAKE_BUILD_TYPE:编译类型(Debug、Release)
  • CMAKE_BINARY_DIRPROJECT_BINARY_DIR_BINARY_DIR:如果为in source build,指工程顶层目录;如果是out of source,指工程编译发生的目录
  • CMAKE_SOURCE_DIRPROJECT_SOURCE_DIR_SOURCE_DIR:无论采用何种编译方式都指工程顶层目录
  • CMAKE_C_COMPILER:指定C编译器
  • CMAKE_CXX_COMPILER:指定C++编译器
  • EXECUTABLE_OUTPUT_PATH:可执行文件输出的存放路径
  • LIBRARY_OUTPUT_PATH:库文件输出的存放路径

2.4 生成静态库/共享库

库分为静态库(Static Library)和共享库(Shared library)两类。静态库文件的扩展名是.a,共享库文件的扩展名是.so(在CYGWIN环境下,分别叫做.o和.dll)。

2.4.1生成静态库

静态库:可重定位目标文件以一种特定的方式打包成一个单独的文件,并且在链接生成可执行文件时,从这个单独的文件中“拷贝”它自己需要的内容到最终的可执行文件中。这个单独的文件,称为静态库。linux中通常以.a(archive)为后缀
CMakeLists.txt:

#设置CMake最低版本为2.5
cmake_minimum_required(VERSION 2.5)

#设置工程名为HELLO
project(HELLO)

#通过hello.cpp生成静态库文件libhello.a
add_library(hello hello.cpp)
[vvvcxjvvv@localhost hello]$ cd build
[vvvcxjvvv@localhost build]$ cmake ../
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vvvcxjvvv/Desktop/cxj_data/mycode/hello/build
[vvvcxjvvv@localhost build]$ make
Scanning dependencies of target hello
[100%] Building CXX object CMakeFiles/hello.dir/hello.o
Linking CXX static library libhello.a
[100%] Built target hello
[vvvcxjvvv@localhost build]$ 

2.4.2 生成共享库

动态库:动态库和静态库类似,但是它并不在链接时将需要的二进制代码都“拷贝”到可执行文件中,而是仅仅“拷贝”一些重定位和符号表信息,这些信息可以在程序运行时完成真正的链接过程。linux中通常以.so(shared object)作为后缀。
CMakeLists.txt编写:

#设置最低cmake版本
cmake_minimum_required(VERSION 2.5)

#设置项目名称为MYFRIEND
project(MYFRIEND)

#定义变量MYFRIEND_SRC为include/myfriend.h src/myfriend.cpp
set(MYFRIEND_SRC include/myfriend.h src/myfriend.cpp)

#将include目录添加进头文件搜索路径(重要!!!否则找不到include/myfriend.h)
include_directories(include)

#通过变量MYFRIEND_SRC生成libMYFRINED_SHARED.so共享库
add_library(MYFRINED_SHARED SHARED ${MYFRIEND_SRC})
[vvvcxjvvv@localhost temp3]$ cd build
[vvvcxjvvv@localhost build]$ cmake ../
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
[vvvcxjvvv@localhost build]$ cmake ../
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vvvcxjvvv/Desktop/cxj_data/mycode/temp3/build
[vvvcxjvvv@localhost build]$ make
Scanning dependencies of target MYFRINED_SHARED
[100%] Building CXX object CMakeFiles/MYFRINED_SHARED.dir/src/myfriend.o
Linking CXX shared library libMYFRINED_SHARED.so
[100%] Built target MYFRINED_SHARED
[vvvcxjvvv@localhost build]$ 

三、使用案例

3.1 单文件直接编译(内部构建)

CMakeLists.txt编写:

#设置CMake最低版本为2.5
cmake_minimum_required(VERSION 2.5)

#设置工程名为HELLO
project(HELLO)

#生成可执行文件hello_cmake(源文件为hello.cpp)
add_executable(hello_cmake hello.cpp)

初始文件目录:

[vvvcxjvvv@localhost hello]$ tree .
.
├── CMakeLists.txt
└── hello.cpp

0 directories, 2 files

执行cmake .——进行内部构建

[vvvcxjvvv@localhost hello]$ cmake .
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vvvcxjvvv/Desktop/cxj_data/mycode/hello
[vvvcxjvvv@localhost hello]$ tree .
.
├── CMakeCache.txt
├── CMakeFiles
│   ├── 2.8.12.2
│   │   ├── CMakeCCompiler.cmake
│   │   ├── CMakeCXXCompiler.cmake
│   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   ├── CMakeSystem.cmake
│   │   ├── CompilerIdC
│   │   │   ├── a.out
│   │   │   └── CMakeCCompilerId.c
│   │   └── CompilerIdCXX
│   │       ├── a.out
│   │       └── CMakeCXXCompilerId.cpp
│   ├── cmake.check_cache
│   ├── CMakeDirectoryInformation.cmake
│   ├── CMakeOutput.log
│   ├── CMakeTmp
│   ├── hello_cmake.dir
│   │   ├── build.make
│   │   ├── cmake_clean.cmake
│   │   ├── DependInfo.cmake
│   │   ├── depend.make
│   │   ├── flags.make
│   │   ├── link.txt
│   │   └── progress.make
│   ├── Makefile2
│   ├── Makefile.cmake
│   ├── progress.marks
│   └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── hello.cpp
└── Makefile

6 directories, 28 files

执行make进行编译:

[vvvcxjvvv@localhost hello]$ make
Scanning dependencies of target hello_cmake
[100%] Building CXX object CMakeFiles/hello_cmake.dir/hello.o
Linking CXX executable hello_cmake
[100%] Built target hello_cmake
[vvvcxjvvv@localhost hello]$ tree .
.
├── CMakeCache.txt
├── CMakeFiles
│   ├── 2.8.12.2
│   │   ├── CMakeCCompiler.cmake
│   │   ├── CMakeCXXCompiler.cmake
│   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   ├── CMakeSystem.cmake
│   │   ├── CompilerIdC
│   │   │   ├── a.out
│   │   │   └── CMakeCCompilerId.c
│   │   └── CompilerIdCXX
│   │       ├── a.out
│   │       └── CMakeCXXCompilerId.cpp
│   ├── cmake.check_cache
│   ├── CMakeDirectoryInformation.cmake
│   ├── CMakeOutput.log
│   ├── CMakeTmp
│   ├── hello_cmake.dir
│   │   ├── build.make
│   │   ├── cmake_clean.cmake
│   │   ├── CXX.includecache
│   │   ├── DependInfo.cmake
│   │   ├── depend.internal
│   │   ├── depend.make
│   │   ├── flags.make
│   │   ├── hello.o
│   │   ├── link.txt
│   │   └── progress.make
│   ├── Makefile2
│   ├── Makefile.cmake
│   ├── progress.marks
│   └── TargetDirectories.txt
├── cmake_install.cmake
├── CMakeLists.txt
├── hello_cmake
├── hello.cpp
└── Makefile

6 directories, 32 files
[vvvcxjvvv@localhost hello]$ ./hello_cmake
Hello World!
[vvvcxjvvv@localhost hello]$ 

3.2 多目录工程直接编译(外部构建)

CMakeLists.txt编写:

#设置最低的cmake版本为2.5
cmake_minimum_required(VERSION 2.5)

#设置项目名称为MYFRIEND
Project(MYFRIEND)

#把源文件目录include添加到工程的头文件搜索路径
include_directories(include)

#生成可执行文件main_cmake,源文件为main.cpp、src/myfriend.cpp
#相当于 g++ main.cpp src/myfriend.cpp -Iinclude -o main
add_executable(main_cmake main.cpp src/myfriend.cpp)

初始目录结构:

[vvvcxjvvv@localhost temp1]$ tree .
.
├── CMakeLists.txt
├── include
│   └── myfriend.h
├── main.cpp
└── src
    └── myfriend.cpp

2 directories, 4 files

创建build文件夹存放输出文件——外部构建

[vvvcxjvvv@localhost temp1]$ mkdir build
[vvvcxjvvv@localhost temp1]$ cd build

使用cmake ../找到顶层目录下的CMakeLists.txt

[vvvcxjvvv@localhost build]$ cmake ../
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vvvcxjvvv/Desktop/cxj_data/mycode/temp1/build

使用make进行编译,产生的可执行文件在build目录下

[vvvcxjvvv@localhost build]$ make
Scanning dependencies of target main_cmake
[ 50%] Building CXX object CMakeFiles/main_cmake.dir/main.o
[100%] Building CXX object CMakeFiles/main_cmake.dir/src/myfriend.o
Linking CXX executable main_cmake
[100%] Built target main_cmake
[vvvcxjvvv@localhost build]$ cd ../
[vvvcxjvvv@localhost temp1]$ tree .
.
├── build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   │   ├── 2.8.12.2
│   │   │   ├── CMakeCCompiler.cmake
│   │   │   ├── CMakeCXXCompiler.cmake
│   │   │   ├── CMakeDetermineCompilerABI_C.bin
│   │   │   ├── CMakeDetermineCompilerABI_CXX.bin
│   │   │   ├── CMakeSystem.cmake
│   │   │   ├── CompilerIdC
│   │   │   │   ├── a.out
│   │   │   │   └── CMakeCCompilerId.c
│   │   │   └── CompilerIdCXX
│   │   │       ├── a.out
│   │   │       └── CMakeCXXCompilerId.cpp
│   │   ├── cmake.check_cache
│   │   ├── CMakeDirectoryInformation.cmake
│   │   ├── CMakeOutput.log
│   │   ├── CMakeTmp
│   │   ├── main_cmake.dir
│   │   │   ├── build.make
│   │   │   ├── cmake_clean.cmake
│   │   │   ├── CXX.includecache
│   │   │   ├── DependInfo.cmake
│   │   │   ├── depend.internal
│   │   │   ├── depend.make
│   │   │   ├── flags.make
│   │   │   ├── link.txt
│   │   │   ├── main.o
│   │   │   ├── progress.make
│   │   │   └── src
│   │   │       └── myfriend.o
│   │   ├── Makefile2
│   │   ├── Makefile.cmake
│   │   ├── progress.marks
│   │   └── TargetDirectories.txt
│   ├── cmake_install.cmake
│   ├── main_cmake
│   └── Makefile
├── CMakeLists.txt
├── include
│   └── myfriend.h
├── main.cpp
└── src
    └── myfriend.cpp

10 directories, 35 files
[vvvcxjvvv@localhost temp1]$ cd build
[vvvcxjvvv@localhost build]$ ./main_cmake
Hello Chandler

3.3 多目录工程生成库编译(外部构建)

CMakelists.txt编写:

#设置最低cmake版本
cmake_minimum_required(VERSION 2.5)

#设置项目名称为MYFRIEND
project(MYFRIEND)

#添加编译参数-g -o2 -std=c++11
add_compile_options(-g -o2 -std=c++11)

#定义变量MYFRIEND_SRC为include/myfriend.h src/myfriend.cpp
set(MYFRIEND_SRC include/myfriend.h src/myfriend.cpp)

#将include目录添加进头文件搜索路径(重要!!!否则找不到include/myfriend.h)
include_directories(include)

#通过变量MYFRIEND_SRC生成libMYFRINED_SHARED.so共享库
add_library(MYFRINED_SHARED SHARED ${MYFRIEND_SRC})

#生成可执行文件main_cmake,源文件为main.cpp
add_executable(main_cmake main.cpp)

#将MYFRINED_SHARED动态库文件链接到可执行文件main_cmake
target_link_libraries(main_cmake MYFRINED_SHARED)

创建build文件夹以把输出文件放入build中
进入build文件夹后执行cmake ../——外部构建

[vvvcxjvvv@localhost temp2]$ mkdir build
[vvvcxjvvv@localhost temp2]$ cd build
[vvvcxjvvv@localhost build]$ cmake ../
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/vvvcxjvvv/Desktop/cxj_data/mycode/temp2/build

执行make进行编译(libMYFRINED_SHARED.so、main_cmake都在build目录下)

[vvvcxjvvv@localhost build]$ make
Scanning dependencies of target MYFRINED_SHARED
[ 50%] Building CXX object CMakeFiles/MYFRINED_SHARED.dir/src/myfriend.o
Linking CXX shared library libMYFRINED_SHARED.so
[ 50%] Built target MYFRINED_SHARED
Scanning dependencies of target main_cmake
[100%] Building CXX object CMakeFiles/main_cmake.dir/main.o
Linking CXX executable main_cmake
[100%] Built target main_cmake
[vvvcxjvvv@localhost build]$ ./main_cmake
Hello Chandler

总结

本文整理了在Linux环境下使用CMake编译C/C++工程文件的一些知识点,整理了CMake编译规则,常用指令以及常用变量,如何使用CMake生成静态库以及共享库。并列举了一些例子展示了如何进行内部构建和外部构建,以及如何对多源文件进行直接编译以及生成库编译。

参考资料

  1. 静态库与动态库区别
  2. 利用CMakeLists.txt文件添加库
  3. Linux下CMake简明教程
  4. CMake官网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【Linux】CMake编译C/C++工程文件 的相关文章

  • vue生命周期图解(带注释)

    vue生命周期图解 xff08 带注释 xff09
  • c++ class和struct的区别是什么?

    c 43 43 class和struct的区别是什么 在c 43 43 中使用struct和class xff0c 定义类的唯一区别就是默认的访问权限 c 43 43 primer第五版 没错 c 43 43 中class和struct几乎
  • 让程序编译更优雅的几个CMake命令

    简介 本文通过一个工程示例介绍了几个让程序编译更优雅的CMake命令 文末有完整下载地址 该工程示例首先生成一个动态库 xff08 libversion dll xff1a 该库主要用于打印版本相关的信息 xff09 xff0c 然后在一个
  • Fast-Planner安装

    Fast Planner安装 Fast Planner是港科大沈老师课题组的项目 xff0c 该项目是为了实现四旋翼无人机能在复杂未知环境下快速飞行 首先到Fast Planner的github网址下 xff0c 查看README xff0
  • Windows程序设计学习笔记——Winsock和udp

    Winsock是处理网络的Windows api 使用前先包含头文件Winsock2 h以及导入静态库Ws2 32 lib include lt Winsock2 h gt pragma comment lib 34 Ws2 32 lib
  • 网络编程04-UDP的广播、组播

    目录 一 UDP广播通信 1 什么是广播 2 特点 3 广播地址 4 实现广播的过程 xff08 一定是使用UDP协议 xff09 广播发送端 广播接收方 练习1 xff1a 把广播通信进行实现 发送端 接收端 二 UDP组播 xff08
  • JSON文件的生成与解析

    参考Json文件的生成和解析
  • C++ 设置double精度

    设置double精度 在这里插入代码片 span class token macro property span class token directive keyword include span span class token str
  • GitLab 出现错误Could not resolve host: xxx-xxx

    错误原因 xff1a 域名解析错误 解决办法找 打开hosts 在最后一行添加 192 30 xxx xxx gitlab
  • TeeChart控件_动态创建

    在安装目录下找到TeeChartxxxxx ocx 以管理员的身份打开cmd 注册TeeChartxxxxx ocx regsvr32 TeeChartxxxxx ocx VS2015 使用TeeChart绘图控件 CRect rect s
  • Nginx

    Nginx 介绍 Nginx是一款轻量级的Web 服务器 反向代理服务器 电子邮件 xff08 IMAP POP3 xff09 代理服务器 xff0c 并在一个BSD like 协议下发行 由俄罗斯的程序设计师Igor Sysoev所开发
  • 上电自动开机

    上电开机启动是指电脑主机在UPS恢复供电时可以自动开机 该功能必须要求电脑主板型号支持 xff0c 进入电脑的BIOS进行设置使用 不同型号的电脑的BIOS设置会有区别 xff0c 以下仅做参考 xff1a 第一步 xff1a 开机进入BI
  • Linux网络编程【TCP】

    文章目录 TCP特点TCP中CS架构TCP状态转换相关操作函数recv函数send函数 TCP特点 TCP是一种面向广域网的通信协议 xff0c 目的是在跨越多个网络通信时 xff0c 为两个通信端点之间提供一条具有下列特点的通信方式 xf
  • 博客资源整理

    文章目录 STLLinux基础命令linux系统编程Linux网络编程Docker容器技术数据库第三方库的使用Linux编程WebQt STL 基础概念 容器 duque stack map set vector 算法 查找算法 排序算法
  • Qt编译Mysql驱动

    1找到源码 2点击编译会看到报错 1解决方案 下载相关文件 也可以私信发给你 2打开配置文件添加下面的信息 相关文件下载 3点击编译 弹出的框直接关掉就行 4在安装qt的根目录下会生成如下目录 5 找到下面的库 6 将上面的库拷贝到如下目录
  • C++中的异常语法

    文章目录 概述异常的关键子自定义异常使用栈解旋异常的接口声明异常变量的生命周期C 43 43 标准异常库 概述 C语言的异常缺陷在于返回值只有一个 xff0c 可能出现二义性 xff0c 没有统一的标准 C 43 43 中的异常必须有处理
  • 处理鼠标连续点击的问题

    处理鼠标连续点击的问题 span class token comment 上次点击时间点 span DWORD m tmClick span class token punctuation span span class token com
  • FLOPS和FLOPs、GFLOPs区别与计算

    参考FLOPS和FLOPs GFLOPs区别与计算
  • VS远程调试

    文章目录 VS远程调试本地和虚拟机调试准备工作 xff1a 需要注意的几个地方 xff1a VS远程调试 在编程中由于环境 版本等各种原因 xff0c 我们需要模拟出来各种环境来跑不同的版本测试 本地和虚拟机调试 准备工作 xff1a 以V
  • AUTOSAR基础篇之CanNM

    前言 首先 xff0c 问大家几个问题 xff0c 你清楚 xff1a 为什么要引入网络管理呢 xff1f 上电同时启动 xff0c 下电同时关闭 xff0c 它不香吗 xff1f 你知道车上的ECU节点可以分为哪几种类型吗 xff1f 汽

随机推荐

  • CANoe应用案例之DoIP通信

    随着ECU功能和存储容量的不断提高 xff0c 主机厂对于ECU诊断和刷写有了更高的要求 由于带宽的限制 xff0c 传统的汽车总线 xff08 如CAN总线 xff09 存在刷写时间过长的缺点 xff0c 大大降低了生产和维修效率 DoI
  • TRACE32——常用操作

    TRACE 32常用操作 TRACE32软件打开后 xff0c 连上硬件环境 xff0c 我们就可以开始尝试和芯片建立连接 xff0c 并进行基本的调试操作 第一步 xff1a 确认目标板是否上电 第二步 xff1a 打开System Se
  • TRACE32——基于SNOOPer的变量记录

    TRACE32 基于SNOOPer的变量记录 在我们日常调试工作中 xff0c 经常会遇到一种场景 xff1a 对于某些变量或者内存的值 xff0c 希望对其进行监控 当这些变量发生写或者读的时候 xff0c 将这些操作记录下来 xff0c
  • TRACE32——内存填充测试Data.Pattern

    TRACE32 内存填充测试Data Pattern Data Pattern 命令可以用于对内存 xff08 SRAM DDR Flash等 xff09 写入随机值 xff0c 以快速地测试内存是否可以正确读写 命令格式 xff1a 示
  • STM32使用printf重定向

    最近用STM32CubeMX创建了一个demo工程 xff0c 在调试过程中 xff0c printf打印功能一直不能正常打印 xff0c 检查工程中也已将fputc函数进行了实现 奇怪的是用JTAG进行调试时打印恢复了正常 最后发现问题的
  • repo的安装和使用

    前言 Android 采用 Gerrit 提供代码评审服务 xff0c 并且开发了一个客户端工具 repo xff0c 实现多仓库管理 Git 的开发者对服务端的 Git 源码做了扩展 xff0c 使得基于 Git xff08 cgit x
  • repo sync之后不能自动 rebase 的定位

    背景 最近在使用repo sync同步代码时老是报告 xff1a branch xxx is published but not merged and is now 1 commits behind 我之前是由推送过一笔提交 xff0c 但
  • git取指定日期log问题

    库上版本有一个重要bug xff0c 使用了如下命令取一个版本 xff1a repo forall c 39 commitID 61 96 git log before 34 2022 12 09 00 00 00 34 1 pretty
  • ROS读取激光雷达点云数据(RS-Lidar为例)

    一 准备工作 xff1a 1 安装ROS xff08 含有rviz xff09 xff1b 2 安装pcl ros pcl xff08 Point Cloud Library xff09 ros 是ROS中点云和3D几何处理的接口和工具 如
  • 标准预定义的宏

    标准预定义宏是由相关的语言标准规定的 xff0c 所以它们可以在所有执行这些标准的编译器中使用 旧的编译器可能不会提供所有这些宏 它们的名字都以双下划线开头 FILE 这个宏扩展为当前输入文件的名称 xff0c 以 C 字符串常数的形式 这
  • Realsense L515使用

    提示 xff1a 文章写完后 xff0c 目录可以自动生成 xff0c 如何生成可参考右边的帮助文档 文章目录 前言一 主要参考二 基本情况 xff08 一 xff09 ubuntu和ROS情况 xff08 二 xff09 主要步骤 总结
  • 电脑前置摄像头运行ORB-SLAM2 Mono

    ROS本地摄像头 下载安装usb cam包 最好将它放在ROS空间的src文件夹下 xff0c 方便管理 git clone https github com bosch ros pkg usb cam git usb cam cd usb
  • ERROR:cannot launch node of type

    当使用roslaunch启动ros节点时 xff0c 如果出现 ERROR cannot launch node of type 这个错误 xff0c 一般原因是由于没有source bashrc 因此工作空间使用 source bashr
  • Ubuntu 18.04 运行PL-VINS

    代码地址 https span class token operator span span class token comment github com cnqiangfu PL VINS span 安装过程出错参考 PL VINS配置
  • rosbag.bag.ROSBagUnindexedException: Unindexed bag

    rosbag bag ROSBagUnindexedException Unindexed bag ROSBAG
  • d435i 相机和IMU联合标定

    一 前提 我们已经对RGB摄像头和IMU进行了单独标定 参考之前博文 RGB标定 IMU kalibr官方WIKI Kalibr 二 准备标定文件 2 1 标定板yaml文件 标定下载链接 Aprilgrid 6x6 0 5x0 5 m u
  • opencv版权nofree问题

    找到3 1 0中cpp文件拷贝到3 4 12中 xff0c 重新cmake编译 xff0c 即可使用 nofree解决方案
  • realsense d435i 自制Euroc数据集

    参考 提取bag Python程序地址 span class token operator span home span class token operator span yang span class token operator sp
  • orb-slam2运行自己数据集

    因为我跑的是双目摄像头 所以首先在orb slam2下找到ros stereo cc文件然后对其中的rostopic节点进行修改 首先先找到自己对应的节点在 自己录制的 bag 数据集下打开终端执行 rosbag info xxx bag在
  • 【Linux】CMake编译C/C++工程文件

    Linux CMake编译C C 43 43 工程文件 文章目录 Linux CMake编译C C 43 43 工程文件前言一 CMake编译工程1 1 两种方式设置编译规则1 2 两种构建方式1 3 CMake构建C C 43 43 工程