开发者

large c++ static library file after linking

开发者 https://www.devze.com 2023-02-17 14:59 出处:网络
I am building a library from my source code which contain both header (.hpp) and source (.cpp) files. I have a make file which compiles all the source files into respective object file individually an

I am building a library from my source code which contain both header (.hpp) and source (.cpp) files. I have a make file which compiles all the source files into respective object file individually and then a library creation (ar rcs ..) statements which combines all the *.o files and builds a static library out of it. T开发者_Python百科he resulting size of the library file is huge (around 17 Mb). Instead when I do g++ -o a.out *.cpp the out file has a size of 1.4 Mb. Is the archiver command (ar rcs) not removing redundant information from all the individual object files ? I also created shared objects and those were small as well, but I need a static library file for my purpose


Try strip the library, the debug and symbol information and tables might take the extra space.

Also, the ar s option might inflate the resulting archive (again, strip, or just don't use ar rcs, just ar rc).


What happens when you link your static library into a final binary? There's a lot of extra data that should get stripped out during the link process into a binary.

0

精彩评论

暂无评论...
验证码 换一张
取 消