Why are my visual Studio.obj files massive in size compared to the output .exe?

As a background, I am an open source project developer, C ++ - a library called openframeworks , that is, a shell for different libraries such as opengl, quicktime, freeImage, etc. In the next issue, we added a C ++ library called POCO, which looks like a boost in a sense that it is an alternative to a java type foundation library.

I just noticed that in this latest release, where I added the POCO library as a statically linked library, the .obj files created during the compilation act are really massive - for example, a few .obj files for really small .cpp files - 2 MB each. Common compiled .obj files are about 12 mb or so. On the other hand, exes that are produced are small - from 300 to 1 mb.

For comparison, the same libraries compiled into code :: blocks produce .obj files that are approximately equal in size in exe - they are all quite small.

Is there something with the connection and the .obj process in the visual studio that I don't understand? for example, is it doing some kind of intellectual pre-binding or other thing adding to the size of .obj? I experimented a bit with settings such as incremental binding, etc., and did not see any changes.

try or understand in advance for any ideas!

-zach


Note: thanks! I just tried dumpbin, which says "anonymous object" and does not return information about the object. this may be the reason ...


Note 2, after checking the above link, the removal of LTCG (communication time code generation / GL). Files files are much smaller, and dumpbin understands them. Thanks again!

+4
c ++ visual-studio-2008 visual-studio
source share
4 answers

I am not an expert in Visual Studio without using it, but I believe that Visual Studio uses connection time optimization, which can lead to quick code execution results, but can cost a lot of space in libraries. In addition, it may be (I do not know the internal components) that debugging information is not deleted until the actual binding phase.

I'm sure someone will come up with a better / more detailed answer.

+1
source share

Perhaps the difference is debugging information.

The compiler displays debugging information in .obj, but the linker does not put this data in .exe or .dll. It is either discarded or placed in .pdb.

In either case, use the Visual Studio DUMPBIN utility in the .obj files to see what's in them.

+1
source share

Object files must 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 means that all object files must contain names for all objects that other object files can reference. However, the executable will need names that are visible outside the library. In the case of a DLL, this means that only names are exported. Saving is binary: fewer names, and these names are present only once in the DLL.

Modern C ++ libraries will use namespaces. These namespaces mean that the names of the objects become longer, since they also include the names of the encapsulating namespaces.

+1
source share

Compiled libraries of obj files will be huge, because they must contain all the functions, classes and templates that your end users can ultimately use.

The executables that reference your library will be smaller because they will only include compiled code that they need to execute. Usually this will be a tiny subset of the library.

0
source share

All Articles