当前位置:网站首页>Cmake compilation option setting in ros2
Cmake compilation option setting in ros2
2022-07-04 04:34:00 【Shoufei loves playing with robots】
There are many compilation options , Here are some common compilation option settings , And explain the function .
Designated to use C++
edition
set(CMAKE_CXX_STANDARD 17)
It can be set as required 11, 14, 17, 20 wait C++
edition .
Set compilation options
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter -g)
Alarm options :
Alarm options | Function description |
---|---|
-Wall | Allow to issue gcc All the useful alarm information provided |
-Wextra | Warn all legitimate but questionable expressions |
-Werror | Treat alarm information as error information |
-pedantic | Allow to issue ANSI C All warning messages listed in the standard |
-w | Turn off all warnings ( It is not recommended to use ) |
-Wfatal-errors | Stop on the first error , Reduce error finding time |
We often see the following error messages after we add that the alarms turn into errors .
error: unused parameter ‘test’ [-Werror=unused-parameter]
error: variable 'begin' set but not used [-Werror=unused-but-set-variable]
There are places where variables are set but not used , You can add the following code to eliminate this type of error .
#define UNUSED(x) (void)(x)
Code generation options :
Code generation options | Description of options |
---|---|
-fPIC | When compiling dynamic libraries , Require position independent code generation (Position-Independent Code). That is, the absolute address is not used in the code , And using relative addresses , So the loader can load it anywhere in memory and execute . If not used -fPIC, The generated code contains the absolute address . When the loader loads it , We need to reposition first , Relocation modifies the content of the snippet , So each process generates a copy of the code snippet . |
-fvisibility=default or hidden | By default , Set up ELF The visibility of the symbol in the image is public or hidden. The default value is default.hidden Can significantly improve the performance of linking and loading shared libraries , Generate more optimized code , Provide near perfect API Output and prevent symbol collisions . It is strongly recommended to use it when compiling shared libraries . |
Code optimization options :
Optimization options | Description of options |
---|---|
-O0 | No optimization . This is the default |
-O1 | Try to optimize compile time and executable size . |
-O2 | Try almost all the optimizations , But not “ Space for time ” Optimization method . |
-O3 | Turn on some more optimization options :-finline-functions, -funswitch-loops and -fgcse-after-reload . |
-O | Equivalents and -O1 |
-Os | Optimize the size of the generated file . open -O2 Open all the options , Except for those that increase the file size . |
-fomit-frame-pointer | Remove all functions SFP(Stack Frame Pointer), That is, the stack frame pointer is not saved when the function is called SFP. Can improve the speed of the program , The price is not to pass backtrace debug . |
-fno-omit-frame-pointer | And -fno-omit-frame-pointer contrary |
Be careful : -O1 open -fomit-frame-pointer Options
Be careful : No special needs , Optimization options can also be set independently , Directly set the following Compile type that will do
Debug
Options :
Debug Options | Description of options |
---|---|
-g | Generate object code with debug information |
-ggdb | Generate gdb specially Debug information with , There will be some. gdb Dedicated extensions |
-gdwarf-2 | produce DWARF version2 Debug information in the format of |
Be careful : No special needs ,Debug
Options can also be set independently , Directly set the following Compile type that will do
Set compilation type
Specify , As shown below :
colcon build --cmake-args '-DCMAKE_BUILD_TYPE=RelWithDebInfo'
There are four types of compilation :
Compile type | Type description | Similar to option set |
---|---|---|
Debug | Code optimization is turned off , Added code debugging information , Increased the warning level | -O0 -g -Wall -D_DEBUG |
Release | The program achieves the best performance , The fastest , But a lot of debugging information is lost | -O2 -DNDEBUG |
RelWithDebInfo | This mode will try to follow Release Pattern compilation of , But it still carries debugging information , It is a compromise between speed and debugging information . | -O0 -ggdb -DNDEBUG |
MinSizeRel | Minimize the size of the execution file , Generally used in embedded scenes | -O1 -DNDEBUG -DMIN_SIZE_REL |
Additional explanation :
DCMAKE_BUILD_TYPE
Configuration and g++
The relationship between compilation options :
DCMAKE_BUILD_TYPE
yes Cmake
Things on the configuration level . The relevant configuration of the final compiled type will be converted to g++
Compilation options .
Reference resources :
https://blog.51cto.com/u_15169172/2710502
If you think it's useful, just praise it !
It's me , One to help everyone Filling pit Robot development siege lion .
In addition, the official account. 《 First flight 》 Internal reply “ robot ” Get carefully recommended C/C++,Python,Docker,Qt,ROS1/2 And other commonly used technical data in the robot industry .
边栏推荐
- 戳气球和布尔运算问题(巨难)
- Rhcsa 06 - suid, sgid, sticky bit (to be added)
- RHCSA 01 - 创建分区与文件系统
- Redis:有序集合zset类型数据操作命令
- RPC技术
- Modstartblog modern personal blog system v5.2.0 source code download
- AcWing第 58 场周赛
- ROS2中CMake编译选项的设置
- Redis:集合Set类型数据的操作命令
- The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
猜你喜欢
十字路口通行优先权,十字路口通行规则图解
Flink learning 7: application structure
leetcode:1314. Matrix area and [2D prefix and template]
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
2020 Bioinformatics | TransformerCPI
多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
Redis:有序集合zset类型数据操作命令
Deep parsing structured exception handling (SEH) - by Matt Pietrek
The "functional art" jointly created by Bolang and Virgil abloh in 2021 to commemorate the 100th anniversary of Bolang brand will debut during the exhibition of abloh's works in the museum
随机推荐
Leetcode skimming: binary tree 09 (minimum depth of binary tree)
C language bidirectional linked list first edition
最长递增子序列问题(你真的会了吗)
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Wobo Union ended its strategic evaluation and decided to retain Bozi's business with excellent performance
Emlog user registration plug-in is worth 80 yuan
Apple CMS imitation watermelon video atmospheric response video template source code
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
Leetcode brush question: binary tree 06 (symmetric binary tree)
两万字带你掌握多线程
Krypton saikr daily question - CTF
优秀的测试/开发程序员是怎么修炼的?该往哪走......
博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
GUI 应用:socket 网络聊天室
Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal
Leetcode brush questions: binary tree 05 (flip binary tree)
JS realizes the effect of text scrolling marquee
Kivy教程之 格式化文本 (教程含源码)
Application scheme of Puyuan ds1000z series digital oscilloscope in communication principle experiment
Detailed explanation of event cycle