On 20/03/2020 22:15, Charles Bailey wrote: > I have been trying to determine why the executable files produced by > MinGW are much larger than I would expect, even for small, simple, > console-mode programs. I tried an experiment with what is probably > the smallest possible C program. Just one line:> > int main(void) {return 0;} For me, cross-compiling this with mingw32-gcc-9.2.0, and the upcoming (yet-to-be-published) mingwrt-5.3.1, yields a 20480 byte executable: $ echo 'int main(void){return 0;}' | mingw32-gcc -s -xc - $ ls -l a.exe -rwxr-xr-x 1 keith keith 20480 Mar 23 18:49 a.exe > When I compile this with TCC I get a .exe file that is just 1,536 > bytes. With gcc from MinGW I get a .exe that is 42,035 bytes long. > Executing the strip command on it to remove debug symbols brings it > down to 19,470 bytes, which is still more than 12 times the size of > the TCC-produced file. So, comparable to my experience, then; (with mingw32-gcc-8.2.0, and mingwrt-5.2.3, I see 19456 bytes). > [...snip...] > > What is all that extra stuff that MinGW is inserting? Why is it > referencing tons of functions that I'm not even using? Eli has already answered this, but some further explanation may be merited: * The DLL imports, on which you seem to be focused, actually have a negligible effect on executable size; the dominant contribution is from MinGW's more comprehensive, more robust, and predominantly statically linked run-time startup -- and perhaps to a lesser extent, shutdown -- code. * The size of the executable may be reduced, at the cost of additional DLL dependencies, by _more_ dynamic linking; for example, libmingwex may be dynamically linked, (supported since mingwrt-5.0, I have libmingwex.dll.a in ./mingwrt/): $ echo 'int main(void){return 0;}' | mingw32-gcc -s -xc - -L ./mingwrt/ $ ls -l a.exe -rwxr-xr-x 1 keith keith 11776 Mar 23 19:14 a.exe > Are there some gcc options I can specify to eliminate that extra > stuff? Yes, but using them is far from trivial: consult GCC documentation for -nostdlib, and related options, but note that if you use them, you will likely need to write your own startup code. -- Regards, Keith. Public key available from keys.gnupg.net Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: OpenPGP digital signature URL: <https://lists.osdn.me/mailman/archives/mingw-users/attachments/20200323/cbeee605/attachment.sig>