0%

Set Up MinGW for Sublime Text 3

Overview

MinGW, a contraction of “Minimalist GNU for Windows”, is a minimalist development environment for native Microsoft Windows applications.
MinGW includes:

  • A port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran compilers;
  • GNU Binutils for Windows (assembler, linker, archive manager);
  • A command-line installer, with optional GUI front-end, (mingw-get) for MinGW and MSYS deployment on MS-Windows;
  • A GUI first-time setup tool (mingw-get-setup), to get you up and running with mingw-get.

Download

Download MinGW

Installation

Select Package

  • mingw-developer-toolkit
  • mingw32-base
  • mingw32-gcc-g++
  • mysy-base

Click: Installation > Apply Changes

Set up environment variables

Name Value
C_INCLUDEDE_PATH C:\MinGW\include
LIBRARY_PATH C:\MinGW\lib
Path C:\MinGW\bin

Debug test.c with cmd

Create a new text code.

1
2
3
4
5
6
7
#include<stdio.h>
int main ()
{
printf("hello world!\n");

return 0;
}

Call gcc in cmd.

gcc test.c -o test

Setup Sublime Text 3

Build a new System

Click: Tools > Build System > New Build System
Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"cmd": ["g++", "${file}", "-o","${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:?(.*)$",
"working_dir": "${file_path}",
"encoding":"cp936",
"selector": "source.c",
"variants":
[
{
"name": "Run",
"cmd": ["cmd","/C","start","cmd","/c", "${file_path}/${file_base_name}.exe &pause"]
}
]
}

Save as C.sublime-build

Compile and Run

Press Ctrl + Shift + B to compile and run, or just press Ctrl + B to run (if it has been compiled).