C ++链接器选项/force使.exe变小? [英] C++ Linker Option /force making smaller .exe ?

查看:95
本文介绍了C ++链接器选项/force使.exe变小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试对stdafx.cpp的一些更改,因此我在自定义链接选项中设置了/force选项.这可以正常工作,但我注意到编译时的.exe比不进行这些更改的情况下编译时的.exe小2MB,这是为什么的任何想法?该代码可以很好地执行,除了我试图进行的一项更改外,没有任何区别.我正在使用MSDEV vs6 c ++ ..
由于使用以下Microsoft文章,因此我正在使用/force选项.. http://support.microsoft.com/kb /245434/pt-b [ ^ ]

I was testing out some changes to stdafx.cpp so I set the /force option in the customize link options. This worked fine but I noticed the .exe when compiled was 2MB smaller than when I compile it without these changes any ideas as to why? The code executes fine and shows no difference other than the one change I was trying to make. I am using MSDEV vs6 c++..
I am using the /force option due to the following Microsoft Article.. http://support.microsoft.com/kb/245434/pt-b[^]

推荐答案

为什么您的更改要求您设置/force选项?

如果链接器没有抱怨,为什么要设置它?实际上,这只是针对程序链接可能存在的问题的一种解决方法.

您是否将编译器警告级别设置为4?如果收到警告,可以解释或删除它们.

您是否使用/MAP选项生成了链接器输出文件? http://msdn.microsoft.com/en-us/library/k7xkk3e2 (v = vs.80).aspx [
Why did your change require you to set the /force option?

If the linker is not complaining why set it? This is really just a workaround for problems that ( may) exist with the linking of your program.

Have you set the compiler warning level to 4? If you are getting warnings can you explain or remove them.

Have you produced a linker output file using /MAP option? http://msdn.microsoft.com/en-us/library/k7xkk3e2(v=vs.80).aspx[^]

If you produce the map file for both conditions (with and without changes) and compare them you will be able to determine what has been linked differently.

Other than that there is no simple answer to your question.

This is because what the /force option does is completely determined by your code and whatever symbols are unresolved or multiply defined.



16-03-2012 You have added this information to your question.

成员3782238写道:
Member 3782238 wrote:

由于以下Microsoft文章,我正在使用/force选项. microsoft.com/kb/245434/pt-b">http://support.microsoft.com/kb/245434/pt-b [
title =新窗口" href ="http://support.microsoft.com/kb/245434/pt-b" target ="_ blank"> ^
]

I am using the /force option due to the following Microsoft Article.. http://support.microsoft.com/kb/245434/pt-b[
title="New Window" href="http://support.microsoft.com/kb/245434/pt-b" target="_blank">^
]




为什么exe大小不同的答案与/FORCE没有关系.这是因为此解决方案需要MFC库的静态链接.您以前可能是动态链接的.通过静态链接,MFC库将添加到您的可执行文件中.静态链接与动态链接将始终生成大小不同的可执行文件.

我先前的答案仍然有效.




The answer as to why the exe is different in size has nothing to do with /FORCE. It is because this solution requires static linking of the MFC library. You were probably dynamically linking before. With static linking the MFC library is added to your executable. Static linking vs dynamic linking will always produce different size executables.

My earlier answer is still valid.


所以您说的是当您使用/fore选项时exe大小减小了2mb?

您是否在程序中使用任何其他.lib?
so you are saying like when you used /fore option exe size is reduced by 2mb?

are you using any other .libs in the program ?


这篇关于C ++链接器选项/force使.exe变小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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