减少可执行文件大小的方法? [英] A way to decrease executable sizes?

查看:82
本文介绍了减少可执行文件大小的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。


如果我们使用源文件
每个函数
,我已经读过可执行文件较小的地方了!

所以,我用gcc进行测试,接缝确认!发生什么接缝是

,如果我们从定义3个其他的源文件调用函数,

链接器包括所有4个函数的代码,即使我们打电话给

并不依赖其他人!


你们对此有什么看法?

是有没有办法让链接器拒绝所有不需要的代码?


如果没有其他任何答案,我可能在将来创建一个小的

应用程序可以在发布模式下用来分隔

中自己文件的所有功能并编译所有这些功能。

请说明你的关于这一点的意见和理论。


PS:如果有人想要它,我可以让测试项目可用。

Hello.

I''ve read somewhere that the executable is smaller if we use a source file
for each function!
So, I tested this with gcc and it seams to confirm! What seams to happen is
that if we call a function from a source-files that defines 3 others, the
linkers includes the code of all the 4 functions, even if the on we call
doesn''t rely on the others!

What do you people think about this?
Is there any way to make the linker reject all the code that isn''t needed?

If there isn''t any other answer to this, I may in the future create a small
app that could be used in release mode to separate all the functions in
their own files and compile all of it.
Please state your opinions and theorys about this.

PS: If someone wants it I can make the test project available.

推荐答案

Filipe Martins写道:
Filipe Martins wrote:
你好。

如果我们使用源
文件,我已经读过可执行文件较小的地方为每个功能!


这可能是这种情况,也可能不是,取决于你的
编译器/链接器。

所以,我测试了这个用gcc和它接缝确认!发生什么接缝是如果我们从定义
3个其他来源的源文件调用函数,则链接器包含所有4个函数的代码,即使
如果我们调用不依赖别人!


是的。

你有什么想法呢?


我认为这没什么关系。首先,在大多数平台上,可执行文件大小并不是很重要。第二,你为什么要编写从未使用过的
函数?

有没有办法让链接器拒绝所有不需要的代码?
Hello.

I''ve read somewhere that the executable is smaller if we use a source
file for each function!
This might be the case or it might not, depending on your
compiler/linker.
So, I tested this with gcc and it seams to confirm! What seams to
happen is that if we call a function from a source-files that defines
3 others, the linkers includes the code of all the 4 functions, even
if the on we call doesn''t rely on the others!
Yes.
What do you people think about this?
I think that it doesn''t matter much. First, executable size doesn''t
really matter much on most platforms. Second, why would you write
functions that are never used?
Is there any way to make the linker reject all the code that isn''t
needed?




这取决于链接器和/或编译器。



That depends on the linker and/or compiler.


Rolf Magnus写道:
Rolf Magnus writes:
如果我们为每个函数使用源
文件,我已经读过可执行文件较小的地方了!
I''ve read somewhere that the executable is smaller if we use a source
file for each function!



这可能是这种情况,也可能不是,取决于您的编译器/链接器。



This might be the case or it might not, depending on your
compiler/linker.

所以,我用gcc和它接缝进行了测试确认!发生什么接缝是如果我们从定义
3个其他来源的源文件调用函数,则链接器包含所有4个函数的代码,即使
如果我们调用并不依赖其他人!
So, I tested this with gcc and it seams to confirm! What seams to
happen is that if we call a function from a source-files that defines
3 others, the linkers includes the code of all the 4 functions, even
if the on we call doesn''t rely on the others!



是的。



Yes.

你们对此有什么看法?


我认为这没什么关系。首先,在大多数平台上,可执行文件大小并不重要。第二,你为什么要编写从未使用过的函数?



I think that it doesn''t matter much. First, executable size doesn''t
really matter much on most platforms. Second, why would you write
functions that are never used?




是否认为调用sin()的程序也会调用tanh() ? ISTM

这是OP正在谈论的事情。



Is it a given that a program that calls sin() will also call tanh()? ISTM
that is the kind of thing the OP is talking about.


2004年4月14日17:25:44 -0700, fi ************ @ free-spy.net ( Filipe Martins)

写道:
On 14 Apr 2004 17:25:44 -0700, fi************@free-spy.net (Filipe Martins)
wrote:
你好。

如果我们使用的话,我已经读过可执行文件较小的地方了源文件
为每个功能!
所以,我用gcc测试了它,接缝确认!接下来要发生的事情是,如果我们从定义了3个其他的源文件调用函数,
链接器包含所有4个函数的代码,即使我们调用了
并不依赖于其他人!

你们对此有何看法?
有没有办法让链接器拒绝所有不需要的代码?如果没有其他任何答案,我可能会在将来创建一个小的
应用程序,可以在发布模式下用来分离自己的所有功能文件并编译所有文件。

请说明您对此的意见和理论。

PS:如果有人想要,我可以提供测试项目。
Hello.

I''ve read somewhere that the executable is smaller if we use a source file
for each function!
So, I tested this with gcc and it seams to confirm! What seams to happen is
that if we call a function from a source-files that defines 3 others, the
linkers includes the code of all the 4 functions, even if the on we call
doesn''t rely on the others!

What do you people think about this?
Is there any way to make the linker reject all the code that isn''t needed?

If there isn''t any other answer to this, I may in the future create a small
app that could be used in release mode to separate all the functions in
their own files and compile all of it.
Please state your opinions and theorys about this.

PS: If someone wants it I can make the test project available.




首先,这是一个偏离主题的话题,因为它确实不是
语言问题。但是出现这种情况,那些创建项目的人应该知道这些工具采用的一般方法。


我的经验并不是很难实现 - 关于最新的

工具和/或项目配置的使用,但这里是我如何看待它:


当你创建一个由几个主要源文件组成的项目,

通常的情况是所有源文件中的所有函数都是程序的重要部分。如果您使用命令行工具并提供

命令,例如:

cl app.cpp more.cpp more2.cpp more3.cpp


然后编译器/链接器驱动程序(在这种情况下它恰好是MSVC')

将所有cpp文件编译成obj文件,然后链接它们全部成为一个

单个可执行文件。 IOW,它并不需要检查依赖项;

显然,这与你用gcc看到的行为相同。


创建对象由许多通用函数组成的文件,你会通常使用某种库管理器实用程序创建一个特殊类型的对象文件
:库 ;文件。在Win32 / etc上,这些将具有

" .LIB"扩展,在Unix上他们将是.a文件等。当这些库文件

在命令行上提供时:


cl app.obj more.obj lib1.lib lbi2.lib


然后链接器中的扩展线索

中的每个函数库是/不是/必须是我们想要的,它只选择实际需要的那些

函数。 IOW,函数基于

依赖项加载。这就是为什么只有你实际/使用/从

标准库中获取的函数才会被加载:它们来自库文件,而不是普通的旧b / b
目标文件。 br />

所以要长篇大论,如果你想让链接器选择并且从一个目标文件中选择
,那就把它变成一个库而不是一个普通的旧的

目标文件。


免责声明:我确定有各种特殊情况,不同的

扩展名,在某些情况下,这会使我说的一些或大部分错误

,但我希望基本的想法是适用的。

-leor

-

Leor Zolman --- BD软件--- www.bdsoft.com

C / C ++,Java,Perl和Unix的现场培训

C ++用户:下载BD软件''免费的STL错误消息解密器:
www.bdsoft.com/tools/stlfilt.html


这篇关于减少可执行文件大小的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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