MinGW = Minimalist GNU for Windows
It provides many tools, but this outlines the process to download the GCC or GNU C Compiler.
- Go to MinGW's home page.
- Click on the downloads tab.
- In the package list, click on the show button next to MinGW Installation Manager.
- In the dropdown, click show on the latest version.
- Then click on the link to download the executable instructor, mingw-get-setup.exe.
- Run the downloaded .exe file.
- Click install.
- Input the desired path (the default is fine), but make sure it has sufficient permissions.
- Make sure that all the options are ticked.
- Then click continue.
- Click Installation and continue.
- This will open up the MinGW installation manager.
- Mark mingw32-gcc-g++-bin for installation.
- Go into All Packages on the left and scroll down to find mingw32-gdb-bin and mark it for installation too.
- Then in the toolbar, click Installation > Apply Changes.
- Click Apply.
- Open up the control panel and search environment variables and click on Edit the system environment variables.
- Click Environment Variables at the bottom of the dialogue.
- In System Variables, select PATH and click Edit.
- Click New and input the installation path for MinGW\bin (ie C:\MinGW\bin).
- To verify the path, open up a command prompt and run the command, gcc --version.
***Note that if you want to run C++ files, simply replace the gcc with g++.
- Open up the command prompt.
- Get a list of all the source files involved in your program, you do not need to compile the header files.
gcc main.c file2.c ...
a.exe
- Open up the command prompt
- Get a list of all the source files involved in your program, you do not need to compile the header files.
gcc -g main.c file2.c ...
gdb a.exe
- The GNU Debugger (gdb) has many commands and a comprehensive list can be found here. These are a few of the basic ones:
- Running the current program:
run arg1 arg2 ...
- Adding a breakpoint:
break [file_name]:[line_number]
- Retargeting the debugger:
target exec a.exe
- List commands:
list
- Quit the debugger:
quit
- Running the current program:
- And during execution (at a breakpoint), here are some other commands:
- Print a variable:
print i
- Continue:
c
orcontinue
- Next:
n
ornext
, executes entire next line as single instruction - Step:
s
orstep
, will step into functions - Stop debugging:
kill
- Print a variable:
- You can also run basic C/C++ commands:
- eg.
print sizeof(double)
will print8
- eg.