2

When compiling an empty c program using MinGW the assembly output contains the line

call __main

what library is this from? I expected linking with msvcrt.dll to work (linking using ld), but as it did not, it must be define elsewhere.

There are many related/practically the same question elsewhere, but none of them (as far as I have seen, been searching for a while now) actually contain the answer to this question, so please double check before marking as duplicate.

rtpax
  • 1,687
  • 1
  • 18
  • 32
  • 1
    I don't know for sure (which is why this is a comment, not an answer) but it _should_ be in `libgcc` or `libgcc_s`, both of which should be provided along with the MinGW compiler. I also don't know what extensions those have in a MinGW environment. If you use the compiler driver to link, rather than invoking `ld` directly, these libraries should be automatically picked up; this is a good idea for several other reasons. – zwol Aug 01 '17 at 15:54
  • @zwol That worked! Thank you, feel free to post an answer that I may accept – rtpax Aug 01 '17 at 15:56

2 Answers2

3

__main should be provided by the libgcc library, which comes with the MinGW compiler.

If you use the compiler driver (that is, the gcc command-line tool) to link your program, rather than invoking ld directly, this library should be automatically added to the link. Using the compiler driver to link is recommended practice for this and several other reasons.

Depending on exactly which version of MinGW you have and which version of GCC it embeds, libgcc or part of it may be a DLL, which you must bundle if you are shipping MinGW-compiled executables.

zwol
  • 135,547
  • 38
  • 252
  • 361
0

On my Windows 10 machine, it is in \Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\8.1.0\libgcc.a which is then linked directly with the executable, so you do not have to include any DLL with you software.