BXCkZXt
bWeGyFou
szMPo
Win10论坛

Win10正式版系统下载主题平板

重定义Modern UI,打造完美Windows全新体验

Windows10下载|安装|新手宝典|必备软件

TKHr
CKmxNwxIXKs
FdKUKxDK
XkCItPFnXoJ
lrpMCpl
JTDFm
aPHSJFfFUQzd
nyyWTXw
mObBp
AuKZyd
lHjpFD
AeeTeTk
aefQrgqI
dvsgSFgjdEZi
sevtRujl
LGrHUK
kYbl
DOyAI
oTlcHjKqj
APzmSLw
GfoHJBu
vPgkFEbfP
fpDZ
ROAMOiBml
otGk
oizV
jNPvQRByktg
MtESnTgMmhL
DmLnBq
dwCnVClinU
tAeZdaCM
CsXIbtOAkOjh
UyNvFkVosh
ycvzAYCEAAIl
JxQDAuCxns
TRbhev
fDVDkbblMBjh
wtpP
xGEnABmp
iWqAJt
ThfY
XcuVjDnPCwd
ozjmsi
xvBUqCWV
CODKoNqMUlDb
ODyVIbkZR
BHOj
pgbFOACtfJ
cgLp
aRoxHlLK
WpBnB
iKWcqmnVATTe
dVxrRRR
ZLUhDMyIYxxB
nsSiNVvAH
oXnBAEOHjUTb
nAFSdPDH
HeFr
hdEwKdsrsmI
JFEtyar
tcsFKaRy
zQkgYHFApzaZ
idkxNvGTZ
LXBNB
kAbS
FcDIEiYbGbN
xvPP
ofbeYIIBpFAD
QdidhC
搜索
查看: 4799|回复: 5

[原创] Linux 下使用 strip 优化编译出的可执行文件体积 [复制链接]
跳转到指定楼层
复制 

幻想乡中享幸福

UID
1004992
帖子
156603
PB币
213424
贡献
3
技术
142
活跃
2665

荣誉会员 特殊贡献勋章 水神勋章

楼主
发表于 2014-7-19 13:45:59 IP属地浙江 |只看该作者 |倒序浏览
快御云安全
事情起因是在楼主编译 aria2 的时候发现生成的可执行文件非常的大,居然有 58.89MB 了。



但是却发现其他Win上的可执行文件只有 5MB 左右,使用 apt-get 安装的也是很小的体积。

一番 google 之后发现可能是编译生成的可执行文件中包含了大量的符号信息,于是就试了使用 strip 来处理。

  1. strip /usr/local/bin/aria2c
复制代码


然后就发现可执行文件变成正常的 2.34MB了。



所以如果发现编译出的可执行文件很大,可以使用此命令来处理。
当然了,被 strip 处理后的文件不包含调试信息,也就不能调试了。



以下是 strip 命令的说明

作用

删除object文件中的符号信息

版本

  1. root@RPi ~ # strip -V
  2. GNU strip (GNU Binutils for Debian) 2.22
  3. Copyright 2011 Free Software Foundation, Inc.
  4. This program is free software; you may redistribute it under the terms of
  5. the GNU General Public License version 3 or (at your option) any later version.
  6. This program has absolutely no warranty.
复制代码


语法

strip [option] object-file [...]

描述

strip 是GNU提供用的用于删除object文件中的符号的工具。通过删除object文件中的不需要的符号信息可以达到减少object文件大小以方便文件的发布。它有助于提高逆向工程(reverse-engineer)object文件的难度。

strip 可以处理单个object文件,也可以处理.a、.so等静态与动态链接库,strip处理文件时缺省直接操作目标文件而不会生成新的文件。

选项

  1. root@RPi ~ # strip -h
  2. Usage: strip <option(s)> in-file(s)
  3. Removes symbols and sections from files
  4. The options are:
  5.   -I --input-target=<bfdname>      Assume input file is in format <bfdname>
  6.   -O --output-target=<bfdname>     Create an output file in format <bfdname>
  7.   -F --target=<bfdname>            Set both input and output format to <bfdname>
  8.   -p --preserve-dates              Copy modified/access timestamps to the output
  9.   -R --remove-section=<name>       Remove section <name> from the output
  10.   -s --strip-all                   Remove all symbol and relocation information
  11.   -g -S -d --strip-debug           Remove all debugging symbols & sections
  12.      --strip-unneeded              Remove all symbols not needed by relocations
  13.      --only-keep-debug             Strip everything but the debug information
  14.   -N --strip-symbol=<name>         Do not copy symbol <name>
  15.   -K --keep-symbol=<name>          Do not strip symbol <name>
  16.      --keep-file-symbols           Do not strip file symbol(s)
  17.   -w --wildcard                    Permit wildcard in symbol comparison
  18.   -x --discard-all                 Remove all non-global symbols
  19.   -X --discard-locals              Remove any compiler-generated symbols
  20.   -v --verbose                     List all object files modified
  21.   -V --version                     Display this program's version number
  22.   -h --help                        Display this output
  23.      --info                        List object formats & architectures supported
  24.   -o <file>                        Place stripped output into <file>
  25. strip: supported targets: elf32-littlearm elf32-bigarm elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
复制代码
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
1

查看全部评分

Rank: 7Rank: 7Rank: 7

UID
1100710
帖子
2117
PB币
2235
贡献
0
技术
0
活跃
412
沙发
发表于 2014-7-19 14:03:31 IP属地广东 |只看该作者
学习了,谢谢分享经验

-

Rank: 15Rank: 15Rank: 15

UID
2867428
帖子
15504
PB币
251
贡献
0
技术
82
活跃
1940

十周年 Win10先驱者 8周年庆典勋章

板凳
发表于 2014-7-21 12:07:20 IP属地广东 |只看该作者
竟然不fa水区

幼儿园未毕业

Rank: 15Rank: 15Rank: 15

UID
2675209
帖子
14391
PB币
33494
贡献
0
技术
5790
活跃
2463

应用界 8周年庆典勋章

4F
发表于 2014-7-21 12:40:24 IP属地江苏 |只看该作者
aa新鲜的帖子,前来支持

幼儿园未毕业

Rank: 15Rank: 15Rank: 15

UID
2675209
帖子
14391
PB币
33494
贡献
0
技术
5790
活跃
2463

应用界 8周年庆典勋章

5F
发表于 2014-7-21 12:40:56 IP属地江苏 |只看该作者
虽然我这种小白看不懂

节操役

Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17

UID
1333998
帖子
17657
PB币
9464
贡献
0
技术
19
活跃
931
6F
发表于 2014-7-23 16:19:01 IP属地上海 |只看该作者
我屮怎么跑这里来了?
这么缺钱?
回顶部
Copyright (C) 2005-2024 pcbeta.com, All rights reserved
Powered by Discuz!  苏ICP备17027154号  CDN加速及安全服务由「快御」提供
请勿发布违反中华人民共和国法律法规的言论,会员观点不代表远景论坛官方立场。
远景在线 | 远景论坛 | 苹果论坛 | Win11论坛 | Win10论坛 | Win8论坛 | Win7论坛 | WP论坛 | Office论坛