9

Are there any free, GCC-compatible suites for Windows that generate standalone executables without external dependencies?

Here are a few that do not fit the bill, ordered by undesirability, least to most:

  • MinGW (MSVCRT.DLL)
  • Cygwin (Cygwin runtime DLLs)
  • DJGPP (NTVDM.EXE; not present on x64 platforms)

Right now I'm leaning towards (and using, albeit tentatively,) MinGW, as it does seem to be the "cleanest" approach. I still am not thrilled with the MSVCRT.DLL dependency, especially as I can and do have to deal with customers running pre-Win2K. (Windows 2000 was the first edition to ship with MSVCRT.DLL) Distributing MSVCRT with the application is not an option.

P.S.: I am aware that there is an attempt to create an MSVCRT replacement for MinGW, but it is still unstable/beta, and has limited functionality; not something I'd feel comfortable using for production applications.

P.P.S.: Answers to the effect of "MSCVRT is usually there anyway," or "Just package the redist" are not constructive answers. The question specifically asks how to AVOID dependencies, not ensure their presence.

Unsigned
  • 9,640
  • 4
  • 43
  • 72
  • 1
    MSVCRT is supposed to installed as part of the redistributable. Even Microsoft tools have this limit when linking the runtime as a DLL as opposed to statically. – Yann Ramin Sep 04 '11 at 20:50
  • Related question: http://stackoverflow.com/questions/3943412/can-i-link-msvcrt-statically-with-mingw – Merlyn Morgan-Graham Sep 04 '11 at 20:50
  • With mingw, can't you statically link with the static libs from the platform SDK? – nw. Sep 04 '11 at 20:52
  • 1
    @Yann Ramin: Distributing MSVCRT with the application is not an option. – Unsigned Sep 04 '11 at 20:52
  • 1
    @Merlyn Morgan-Graham: Helpful, but I'm looking for alternatives to MinGW, moreso than static linking. – Unsigned Sep 04 '11 at 20:55
  • 1
    @nw: Not to my knowledge, due to copyright reasons. – Unsigned Sep 04 '11 at 20:56
  • 1
    Why is distributing CRT not an option? Link to a newer version and provide a redist. – Cat Plus Plus Sep 04 '11 at 20:59
  • 2
    @Unsigned: Static linking (if it works out) would solve the problem. MinGW is probably one of the more mature options you have, and I'd hate to have to ditch it over something as simple as this. Your order of preference seems to agree with this :) – Merlyn Morgan-Graham Sep 04 '11 at 21:00
  • 1
    You still have to deal with customers running pre-Win2K? Owch. You won't find any compiler suites still looking to deal with that. – Puppy Sep 04 '11 at 21:02
  • Have you actually found a Windows installation without "msvcrt.dll"? – Cheers and hth. - Alf Sep 04 '11 at 21:06
  • I think when the poster refers to MSVCRT he/she refers to the version that ships with Windows. It's almost impossible to find a win 9x machine without MSVCRT. – David Heffernan Sep 04 '11 at 21:07
  • 1
    @Alf P. Steinbach: Yes, more than I care to recount. – Unsigned Sep 04 '11 at 21:07
  • 1
    @David Heffernan: You'd be surprised. I have had a considerable number of support cases involving Windows 9x without MSVCRT. Hence the question. – Unsigned Sep 04 '11 at 21:09
  • @Cat Plus Plus: A redistributable isn't an option within the constraints we're working in. – Unsigned Sep 04 '11 at 21:10
  • If you can't abide redistributables then just use static linking. – David Heffernan Sep 04 '11 at 21:11
  • 1
    @Cat Plus Plus: Because of internal deployment confines. Redistributables have been proposed and ruled out already. – Unsigned Sep 04 '11 at 21:58
  • 1
    @UnsignedCodeLabs: You should still be able to manually link your object file with the static version of libc. Just download the platform SDK and manually link with libcmt.lib from there. Should work unless you are using are trying to pass some certain CRT stuff (file handles, for one, not sure what else) to or from a DLL. – nw. Sep 05 '11 at 00:43

1 Answers1

11

To avoid MSVCRT with MinGW, use the following flags for the linker:

-nostdlib -Wl,--exclude-libs,msvcrt.a -Wl,-eWinMain

Notice that you have to declare a function named WinMain (you can also choose another name for it) which will be your main. You also can't use any of the standard functions like strlen, printf and friends. Instead, you must use the WinAPI equivalents like lstrcmp, wsprintf, etc.

You can see an example of this using SCons at:

https://sourceforge.net/p/nsis/code/6160/tree/NSIS/trunk/SCons/Config/gnu

I've used this for my project that also requires Windows 9x compatibility. This also has the nice side effect of having smaller executables. From your comments above, it seems you're looking for that too. If that's the case, there are even more tricks you can use in the file I linked above.

Microsoft has a table matching CRT functions to WinAPI at the following KB99456:

Win32 Equivalents for C Run-Time Functions (Web Archive)

More information on getting rid of CRT (although for VC, it can still help) at:

http://www.catch22.net/tuts/win32/reducing-executable-size

Sean Leather
  • 1,182
  • 1
  • 9
  • 25
kichik
  • 33,220
  • 7
  • 94
  • 114
  • 1
    I would have liked to see more along the lines of static linking with libcmt.lib as well, but good answer nonetheless. – Unsigned Sep 09 '11 at 15:29
  • 1
    Awesome, not attempted this yet but I've been looking all over for this info, people even said my question about this was a dup! http://stackoverflow.com/questions/23218931/build-mingw-console-application-without-crt?lq=1 – paulm Apr 30 '14 at 17:42