- 后来, 杰瑞。 宇宙是自己想象的虚构。 br /> Out of curiosity, I wanted to test executable file sizes of the sameprogram from different compilers...The 2 compilers I tested (both old, on purpose) were Borland C++ 3.1and DJGPP 2.03...The program was nothing but a simple hello world program using theiostream header file...I compiled and linked (both copies) with those 2 differentcompilers... The Borland c++ 3.1 compiler gave me an executable withsize like 20-30KB (i don''t remember) and DJGPP gave me an executablewith size like 220-240KB...I can assume 2 things here... Either DJGPP produces WAY morecompicated executables (kind of odd though) or DJGPP''s header filescontain kinda different info....Anyone seen anything like that? Anyone know why? 解决方案Nope, most likely the different has nothing to do with the executable codenor the header files. I suspect in one case you have the library code includedin the executable and in another they are in seperate runtime file (DLL or shared library).On little trivial programs the size of the runtime libraries dwarf the user code.One thing that may explain the difference you are seeing is that onecompiler stores the debug information in the executable itself while theother stores the debug information in a separate file. You are morelikely to get more sensible numbers if you do an optimized build withoutdebug information with both compilers.For small and even medium sized programs the runtime library oftenaccounts for a large part of the executable size. With small programsyour own code accounts for only a very small fraction of the totalexecutable size (I would be surpriced if it would be more than 200bytes). Because you only tested with a small program, it is important torealize that the executable sizes you find are not necessarillyrepresentative for larger programs. If you do the same test with a large(non-trivial) program, it is likely that the difference between the twocompilers has become smaller. Whether the runtime library is linkedstatically or dynamically can make a big difference. Using a differentruntime library can dramatically reduce the executable size of smallprograms. I have been able to produce executables with MSVC as small as2.5 KB using the libtinyc runtime library (compared to 28KB with thestandard runtime library).The quality of the linker and the linker settings may have some impacton the executable size as well. Finally optimization settings of thecompiler may make a (small) difference too.If you really are interested in making your executables as small aspossible, you may find this page an interesting read: http://freespace.virgin.net/james.br...als/minexe.htm--Peter van Merkerkpeter.van.merkerk(at)dse.nlBC++ 3.1 produces native DOS executables. DJGPP produces executablesfor a DOS extender, which is basically a small, simple OS that getslinked into your executable. Most of what you''re seeing in the DJGPPexecutable is the DOS extender code.The DOS extender primarily allows your program to access large amountsof memory directly, compared to the BC++ 3.1 program, which is limitedto 640K, even if your machine has hundreds of megabytes of RAM.--Later,Jerry.The universe is a figment of its own imagination. 这篇关于不同的C ++编译器exec。大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 09:35