mingw cross-compiling
MinGW: Minimalist GNU for Windows
MinGW, "Minimalist GNU for Windows", is a minimalist development environment for native Microsoft Windows applications. It provides a subset of the functionality of GNU, but is designed to operate within the Windows operating system.
Installation:
MinGW can be installed via various methods:
Directly from the MinGW website
Through package managers like MSYS2
After installation, add the MinGW's bin directory to your system's PATH environment variable.
Cross-compiling with MinGW:
To cross-compile, the syntax is similar to GCC and G++, but you use mingw32-gcc or mingw32-g++:
mingw32-gcc [options] source.c -o output.exe
mingw32-g++ [options] source.cpp -o output.exeThe compiled '.exe' file can be run natively on a Windows system.
Common MinGW Commands:
-o: Outputs to a given filename.mingw32-gcc source.c -o output.exe mingw32-g++ source.cpp -o output.exe-c: Compile or assemble the source files, but do not link.mingw32-gcc -c source.c mingw32-g++ -c source.cpp-I: Adds include directory path.mingw32-gcc -I path/to/include source.c -o output.exe mingw32-g++ -I path/to/include source.cpp -o output.exe-L: Adds library directory path.mingw32-gcc -L path/to/library source.c -o output.exe mingw32-g++ -L path/to/library source.cpp -o output.exe-l: Links the library.mingw32-gcc source.c -l library_name -o output.exe mingw32-g++ source.cpp -l library_name -o output.exe-Wall: Enables all compiler's warning messages.mingw32-gcc -Wall source.c -o output.exe mingw32-g++ -Wall source.cpp -o output.exe-g: Generate debug information to use with GDB.mingw32-gcc -g source.c -o output.exe mingw32-g++ -g source.cpp -o output.exe-std: Specifies the language standard.mingw32-gcc -std=c99 source.c -o output.exe mingw32-g++ -std=c++11 source.cpp -o output.exe-mwindows: Create a GUI application instead of a console application.mingw32-gcc -mwindows source.c -o output.exe mingw32-g++ -mwindows source.cpp -o output.exe
Including Libraries:
The process is the same as GCC/G++. For example, to compile a program 'program.c' with a library 'libfoo' located at '/path/to/lib' and headers at '/path/to/include', use:
This will generate a Windows executable 'program.exe' that links to the 'libfoo' library.
Important Note:
MinGW provides Windows ports of many
Last updated