为什么与输出 .exe 相比,我的 Visual Studio .obj 文件很大? [英] why are my visual studio .obj files are massive in size compared to the output .exe?

查看:27
本文介绍了为什么与输出 .exe 相比,我的 Visual Studio .obj 文件很大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为背景,我是一个开源项目的开发人员,一个名为 openframeworks,它是对不同库的封装,如opengl、quicktime、freeImage 等.在下一个版本中,我们添加了一个名为POCO 的c++ 库,它在某些方面类似于boost,因为它是java 的替代品基础库类型功能.

As a background, I am a developer of an opensource project, a c++ library called openframeworks, that is a wrapper for different libraries, like opengl, quicktime, freeImage, etc. In the next release, we've added a c++ library called POCO, which is similar to boost in some ways in that it's an alternative for java foundation library type functionality.

我刚刚注意到,在我将 POCO 库添加为静态链接库的最新版本中,编译过程中生成的 .obj 文件非常庞大 - 例如,几个 .obj非常小的 .cpp 文件的文件是每个 2mb.整体编译的 .obj 文件大约为 12mb 左右.另一方面,生成的 exe 很小 - 300k 到 1mb.

I've just noticed, that in this latest release where I've added the POCO library as a statically linked library, the .obj files that are produced during the act of compilation are really massive - for example, several .obj files for really small .cpp files are 2mb each. The overall compiled .obj files are about 12mb or so. On the flip side, the exes that are produced are small - 300k to 1mb.

相比之下,在 code::blocks 中编译的同一个库生成的 .obj 文件在 exe 中的大小大致相同 - 它们都相当小.

In comparison, the same library compiled in code::blocks produces .obj files that are roughly the same size at the exe - they are all fairly small.

链接和 Visual Studio 中的 .obj 过程是否发生了一些我不明白的事情?例如,它是否在执行某种智能预链接或其他增加 .obj 大小的操作?我已经尝试了一些设置,例如增量链接等,但没有看到任何变化.

Is there something happening with linking, and the .obj process in visual studio that I don't understand? for example, is it doing some kind of smart prelinking, or other thing, that's adding to the .obj size? I've experimented a bit with settings, such as incremental linking, etc, and not seen any changes.

预先感谢您提供任何尝试或见解的想法!

thanks in advance for any ideas to try or insights !

-扎克

注意:非常感谢!我刚刚试过,dumpbin,上面写着匿名对象"并且不返回有关该对象的信息.这个可能是原因....

note: thanks much! I just tried, dumpbin, which says "anonymous object" and doesn't return info about the object. this might be the reason why....

注意 2,在查看上述链接后,删除 LTCG(链接时间代码生成 -/GL)后,.obj 文件要小得多,dumpbin 可以理解它们.再次感谢!!

推荐答案

目标文件需要包含足够的链接信息.在 C++ 中,这是基于名称的.如果两个对象文件使用相同的名称,则它们引用同一个对象(数据/函数/类).这意味着所有目标文件必须包含可能被其他目标文件引用的所有目标的名称.但是,可执行文件需要从库外部可见的名称.对于 DLL,这意味着仅导出名称.节省是双重的:名称较少,而且这些名称在 DLL 中只出现一次.

Object files need to contain sufficient information for linking. In C++, this is name-based. Two object files refer to the same object (data/function/class) if they use the same name. This implies that all object files must contain names for all objects that might be referenced by other object files. The executable however will need the names visible from outside the library. In case of a DLL, this means only the names exported. The saving is twofold: there are less names, and those names are present only once in the DLL.

现代 C++ 库将使用命名空间.这些命名空间意味着对象名称变得更长,因为它们也包括封装命名空间的名称.

Modern C++ libraries will use namespaces. These namespaces mean that object names become longer, as they include the names of the encapsulating namespaces too.

这篇关于为什么与输出 .exe 相比,我的 Visual Studio .obj 文件很大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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