Skip to content

Instantly share code, notes, and snippets.

@alandsilva26
Last active June 7, 2024 18:40
Show Gist options
  • Save alandsilva26/53cd2fecf253554c2f671766d3df5d66 to your computer and use it in GitHub Desktop.
Save alandsilva26/53cd2fecf253554c2f671766d3df5d66 to your computer and use it in GitHub Desktop.
Instructions for installing GCC Compiler on Windows

Installation

To check if GCC already exists by running the following command in your command promt gcc -v

  • Install MSYS2 MSYS2.

  • This will install the linux shell on your Machine.

  • Update packages and mirrors using pacman -Syu.

  • You may have to restart

  • To install GCC copy the following code and paste in the shell Ctrl + v might not work

  • Note: Keep pressing ENTER to select the default installation instructions.

pacman -S --needed base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain \git subversion mercurial \mingw-w64-i686-cmake mingw-w64-x86_64-cmake
  • This command will take a while to download and install all files.
  • After this GCC is installed but you still need to add it to your path.
  • Note: IF you get the following error gcc is not recognized as an internal or external command GCC may not be added to your path

PATH

  • To set the path to GCC Compiler

  • Open Start and type environment variables

  • Click Advanced System Settings

  • Click Environment Variables

  • In the System variables section add a new entry to PATH/ Path.

  • Add the following two lines

  • C:\msys64\mingw64\bin and C:\msys64\ming32\bin

  • Note: The path may vary according to where you have installed MSYS2

  • GCC installation is complete you may use gcc to compile programs If you still get this error gcc is not recognized as an internal or external command try this

Compiling

Locate your program
I will be giving this example considering .c program
cd into your desired directory where file is locate or type cmd in the adress bar
then type command
gcc -o name name.c
eg. gcc -o helloworld helloworld.c
The name after -o is the name given to exe file that is generated
Correct errors if any and run the above command again when done
If no errors are generated
Type name that is the name of your .exe
the program will have run

CODE::BLOCKS

You could also download CODE::BLOCKS IDE which comes with the GCC compiler
Download the binary release from here
Download the one that says mingw-setup.exe
Make sure that you dont have gcc previously installed in your computer
Follow the instructions
You will have to set the path manually as we did previously
The bin lies in C:\Program Files(x86)|CodeBlocks\MinGW\bin

MinGW
MSYS2
GCC
CodeBlocks
More
Installing CodeBlocks

Thank you

@adambala
Copy link

C:\msys64\mingw64\bin and C:\msys64\ming32\bin

Typo: I think there should be C:\msys64\mingw32\bin

@almorshidi0
Copy link

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment