什么是编译器选项和编译器选项?其他减少静态库大小的机制?
什么是编译器选项和编译器选项?其他减少静态库大小的机制?
操作系统:VxWorks 编译器:GCC 语言:C
What are the Compiler Options & Other mechanism for reducing the static library size?
OS : VxWorks
Compiler : GCC
Language : C
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用
-Os
优化较小的代码大小,并省略-g
和任何其他调试选项。Use
-Os
to optimise for smaller code size, and leave out-g
and any other debug options.如果您确实关心链接静态库后的可执行文件大小,那么您还应该在每个源文件(以及目标文件)中仅放置一个函数。链接器通常在链接期间从静态库中提取整个目标文件。
If you're really concerned with the executable size after linking a static library then you should also put only one function in each source file (and hence object file). Linkers usually pull entire object files out of a static library during linking.
您确定需要在最终映像中包含静态库吗?静态库在链接时链接到可执行文件中,因此除非您要创建一个具有工作编译器/链接器的系统,否则您可以安全地删除静态库。动态库是另一个故事......
如果您需要减少静态库的大小,请使用带有正确选项的“strip”。没有任何选项的“strip mylib.a”应该做正确的事情,但是您可能会得到一个带有一些额外选项的较小的库。请小心,不要从库中删除符号表,因为链接器需要此表来发挥其“魔力”。
Are you sure you need to include the static libs in you final image? The static libs are linked into the executable at link time, so unless you are going to make a system with a working compiler/linker you can safely remove the static libraries. Dynamic libs is another story ...
If you need to reduce the size of the static libraries, use "strip" with the right options. "strip mylib.a" without any options should do the right thing, but you might get a smaller library with a few extra options. Be careful so that you don't remove the symbol table from the library since the linker needs this table to do its "magic".
您可以使用
--ffunction-sections
和--fdata-sections
,它告诉 gcc 将每个函数和全局数据变量放在对象内的单独部分中。您不必修改所有源文件。You can use
--ffunction-sections
and--fdata-sections
, which tells gcc to put each function and global data variable in a separate section inside the object. You don't have to modify all your source files.