'Using Git Bash unable to compile C code: "gcc:command not found"

I am trying to compile a winsock code using git bash as a terminal I installed MINGW and git bash lstest version but when I use gcc main.c -o main.exe it gives gcc:command not found



Solution 1:[1]

Use windows terminal instead of git bash. Git bash can't run gcc command. I have also faced the same problem. Hope you will find your solution.

Solution 2:[2]

I was having a similar problem - assuming you are using windows, make sure your downloaded MinGW folder is in your GIT folder (C:\Program Files\Git\MinGW). I then copied the bin folder from MinGW into the mingw64 (C:\Program Files\Git\mingw64\bin) bin folder - which then recognized gcc as a command.

One issue to note that I am still having, is when I try to compile files and create object files using the -o flag, I am not creating anything. I'm still looking into this, but I hope some of this instruction helped to at least get the command recognized.

Some useful links: https://yichaoou.github.io/tutorials/software/2016/06/28/git-bash-install-gcc#:~:text=%20How%20to%20install%20gcc%20in%20Git%20Bash,you%20want%20to%20click%20on%20Apply.%20More%20

https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058#:~:text=The%20basic%20idea%20is%20that%20C%3A%5CProgram%20Files%5CGit%5Cmingw64%5C%20is,the%20Git%20Bash%20icon%20and%20open%20file%20location.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Abidur Rahman Arko
Solution 2 Boylej