G ++编译器标志,以减少二进制文件的大小 [英] g++ compiler flag to minimize binary size

查看:469
本文介绍了G ++编译器标志,以减少二进制文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Arduino乌诺R3。我对每个使用C ++我的传感器使逻辑对象。 Arduino的非常有限的板载内存32KB *和平均,我的编译对象现身6KB左右*。

I'm have an Arduino Uno R3. I'm making logical objects for each of my sensors using C++. The Arduino has very limited on-board memory 32KB*, and, on average, my compiled objects are coming out around 6KB*.

我已经在使用所需的最小的可能的数据类型,以试图最小化我的内存占用。是否有一个编译器标志,以减少二进制文件的大小,或者我需要用更短的变量和函数名,少的功能等,以最大限度地减少我的code基?

I am already using the smallest possible data types required, in an attempt to minimize my memory footprint. Is there a compiler flag to minimize the size of the binary, or do I need to use shorter variable and function names, less functions, etc. to minimize my code base?

此外,对于减少二进制文件的大小其他任何提示或建议的话将是AP preciated。

Also, any other tips or words of advice for minimizing binary size would be appreciated.

*它可能不是以KB来衡量(因为我没有它坐在我面前),但是1对象大约是我的内存总容量,这是促使我关心的1/5。

*It may not be measured in KB (as I don't have it sitting in front of me), but 1 object is approximately 1/5 of my total memory size, which is prompting my concern.

推荐答案

有大量的技术来降低除了什么 us2012 等人在评论中提到的二进制文件的大小,总结起来有我自己的一些要点:

There are lots of techniques to reduce binary size in addition to what us2012 and others mentioned in the comments, summing them up with some points of my own:


  • 使用 -Os 来让GCC / G ++优化的大小。

  • 使用 -ffunction截面-fdata截面每个功能或数据分离成翻译单元中不同的部分。与轮候册,链接器选项结合起来 - GC-部分来摆脱任何未引用部分

  • 运行至少有以下选项: -s -R的.comment -R .gnu.version 。它可与组合 - 带 - 不需要来删除不需要的重定位处理所有符号

  • Use -Os to make gcc/g++ optimize for size.
  • Use -ffunction-sections -fdata-sections to separate each function or data into distinct sections within the translation unit. Combine it with the linker option -Wl,--gc-sections to get rid of any unreferenced sections.
  • Run strip with at least the following options: -s -R .comment -R .gnu.version. It can be combined with --strip-unneeded to remove all symbols that are not necessary for relocation processing.

这篇关于G ++编译器标志,以减少二进制文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆