Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows GNU compiler suite without external dependencies

Tags:

windows

gcc

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.

like image 304
Unsigned Avatar asked Sep 04 '11 20:09

Unsigned


People also ask

Is G ++ and GCC the same?

DIFFERENCE BETWEEN g++ & gccg++ is used to compile C++ program. gcc is used to compile C program.

What is GCC compiler in Windows?

The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, Go, and D, as well as libraries for these languages (libstdc++,...). GCC was originally written as the compiler for the GNU operating system.

Which is better GCC or G ++?

When referring to C++ compilation, it is usual to call the compiler “G++”. Since there is only one compiler, it is also accurate to call it “GCC” no matter what the language context; however, the term “G++” is more useful when the emphasis is on compiling C++ programs.


1 Answers

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

like image 158
kichik Avatar answered Sep 17 '22 08:09

kichik