What are the Compiler Options & O开发者_高级运维ther mechanism for reducing the static library size?
OS : VxWorks Compiler : GCC Language : C
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.
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".
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.
精彩评论