Skip to content
Search

MinGW

lastmod 2019-04-26created 2014-01-0530 edits

MinGW is a collection of GNU software tools ported to Microsoft Windows. It is also known as mingw32.

MinGW includes header files that implement the Windows API, allowing developers to use GCC, a "freely usable" compiler. Whereas with the Cygwin port the compiled program depends on a runtime that emulates Unix-like functionality, MinGW can build Microsoft Windows-based programs without depending on such functionality.

The MinGW project maintains and distributes two basic packages. First, the ported GCC compilers can be used from the Windows command line or integrated into an IDE. Second, you can use MSYS (short for minimal system), which provides a lightweight Unix-like shell environment. This environment bundles enough POSIX tools to run rxvt and autoconf scripts.

The two packages were originally forks of part of Cygwin, and the forks provide more comprehensive Unix-like support thanks to native Windows functionality. Both packages are free software. The Win32 header files are released into the public domain, while the programs ported from GNU are available under the GNU General Public License. Binaries of the complete MSYS package and the individual MinGW GNU utilities can be downloaded from the MinGW site.

Categories

Installing MinGW

You can use mingw-get to download other packages related to mingw. For example, to install GDB, enter the following.

mingw-get.exe install gdb

Hiding the console window in Windows programming

Add -mwindows to the linker options.

For other platforms, see C++:Troubleshooting#Hide terminal window.

Removing the mingw10.dll dependency

Passing -mthreads as an option introduces the dependency. The -mthreads option is only meaningful when __gthread_key_create is needed.

The gcc manual says:

-mthreads
Support thread-safe exception handling on Mingw32. Code that relies on thread-safe exception handling must compile and link all code with the -mthreads option. When compiling,
-mthreads defines -D_MT; when linking, it links in a special thread helper library -lmingwthrd which cleans up per thread exception handling data.

Mingw-w64/w32 specifics

When running an autotools configure script, these options will come in handy:

  • for a 64-bit build: --host=x86_64-w64-mingw32
  • for a 32-bit build: --host=i686-w64-mingw32

If you are experiencing problems, you can also set --build to the same value. Some configure scripts also use --target instead of --host. Use configure --help to get all possible options.

--host, --target, and --build explained

--host specifies on what platform/architecture the compiled program is going to run. --target specifies the platform/architecture that the program should be configured for and will be compiled for. This should only have effect when building cross-compilers. --build specifies the platform/architecture the build process is going to be executed.

DLLs dragging in LIBSTDC++-6.DLL and LIBGCC_S_DW2-1.DLL?

Running an executable compiled with MinGW introduces dependencies on libgcc_s_dw2-1.dll and libstdc++-6.dll. To remove these dependencies, you need to link statically. Add the following LINK FLAGs.

  • -static-libgcc
  • -static-libstdc++

How to create import library

The import library created by the --out-implib linker option.

MinGW Preprocessor

MinGW can be detected in the preprocessor as follows.

#ifdef __GNUC__
#ifdef __MINGW32__

MSVC and MinGW DLLs

gcc -shared -o testdll.dll testdll.c -Wl,--output-def,testdll.def,--out-implib,libtestdll.a
lib /machine:i386 /def:testdll.def
cl testmain.c testdll.lib
cl /LD testdll.c
gcc -o testmain testmain.c testdll.lib

Cross Compile

$ sudo apt-get install mingw-w64

## C
$ i686-w64-mingw32-gcc hello.c -o hello32.exe      # 32-bit
$ x86_64-w64-mingw32-gcc hello.c -o hello64.exe    # 64-bit

## C++
$ i686-w64-mingw32-g++ hello.cc -o hello32.exe     # 32-bit
$ x86_64-w64-mingw32-g++ hello.cc -o hello64.exe   # 64-bit

Tcltk Blog - Mingw Tutorials

Mingw-related material from the Tcltk blog.

  1. http://blog.tcltk.co.kr/?cat=5 - Tcltk_blog_mingw01.pdf
  2. http://blog.tcltk.co.kr/?cat=5&paged=2 - Tcltk_blog_mingw02.pdf
  3. http://blog.tcltk.co.kr/?cat=5&paged=3 - Tcltk_blog_mingw03.pdf
  4. http://blog.tcltk.co.kr/?cat=5&paged=4 - Tcltk_blog_mingw04.pdf
  5. http://blog.tcltk.co.kr/?cat=5&paged=5 - Tcltk_blog_mingw05.pdf
  6. http://blog.tcltk.co.kr/?cat=5&paged=6 - Tcltk_blog_mingw06.pdf
  7. http://blog.tcltk.co.kr/?cat=5&paged=7 - Tcltk_blog_mingw07.pdf
  8. http://blog.tcltk.co.kr/?cat=5&paged=8 - Tcltk_blog_mingw08.pdf
  9. http://blog.tcltk.co.kr/?cat=5&paged=9 - Tcltk_blog_mingw09.pdf
  10. http://blog.tcltk.co.kr/?cat=5&paged=10 - Tcltk_blog_mingw10.pdf
  11. http://blog.tcltk.co.kr/?cat=5&paged=11 - Tcltk_blog_mingw11.pdf
  12. http://blog.tcltk.co.kr/?cat=5&paged=12 - Tcltk_blog_mingw12.pdf
  13. http://blog.tcltk.co.kr/?cat=5&paged=13 - Tcltk_blog_mingw13.pdf
  14. http://blog.tcltk.co.kr/?cat=5&paged=14 - Tcltk_blog_mingw14.pdf
  15. http://blog.tcltk.co.kr/?cat=5&paged=15 - Tcltk_blog_mingw15.pdf

Troubleshooting

A summary of problems that can occur while using MSYS and MinGW, and how to solve them.

directory path

Avoid spaces in directory paths whenever possible.

MinGW may have problems with paths containing spaces, and if not, usually other programs used with MinGW will experience problems with such paths. Thus, we strongly recommend that you do not install MinGW in any location with spaces in the path name reference. You should avoid installing into any directory or subdirectory having names like "Program Files" or "My Documents", etc.

See also

Favorite site

Libraries

MinGW-w64 libraries

References


  1. Setting-up-the-MinGW-w64-environment.pdf ↩

  2. Mingw_dev_env_flags.pdf ↩

  3. MinGW-w64_-_libraries_0.pdf ↩

  4. MinGW-w64_-_libraries_1.pdf ↩

  5. MinGW-w64_-_libraries_2.pdf ↩

  6. MinGW-w64_-_libraries_boost.pdf ↩

author Zer0 sitemap