当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Exercises in quantum mechanics

Leetcode skimming: binary tree 08 (maximum depth of n-ary tree)

优秀的测试/开发程序员是怎么修炼的?该往哪走......
![[microservice openfeign] @feignclient detailed explanation](/img/8d/83bcde1355366c7c88a7a9ade7f9eb.png)
[microservice openfeign] @feignclient detailed explanation

两万字带你掌握多线程

5张图告诉你:同样是职场人,差距怎么这么大?

统计遗传学:第三章,群体遗传

Statistical genetics: Chapter 3, population genetics

【微信小程序】好看的轮播图组件

leetcode:1314. 矩阵区域和【二维前缀和模板】
随机推荐
RHCSA 07 - 用户与群组管理
(pointer) write a function to compare the size of strings by yourself, which is similar to StrCmp.
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
EventBridge 在 SaaS 企业集成领域的探索与实践
Talking about what a high-quality little red book copy needs to have
[Yugong series] go teaching course 002 go language environment installation in July 2022
MIN_ RTO dialog
The interactive solution of JS and app in the H5 page embedded in app (parameters can be transferred and callbacks can be made)
GUI 应用:socket 网络聊天室
Architecture training graduation design + summary
多位科技公司创始人向Entrepreneur First提供高达1.58亿美元的C轮融资,协助其投资下一代全球创新者
[microservice openfeign] use openfeign to remotely call the file upload interface
【安全攻防】序列化与反序列,你了解多少?
How to telecommute more efficiently | community essay solicitation
最长递增子序列问题(你真的会了吗)
leetcode:1314. 矩阵区域和【二维前缀和模板】
(指針)自己寫一個比較字符串大小的函數,功能與strcmp類似。
毕业设计项目
A beautiful API document generation tool