5

I am very new to coding (trying to teach myself C). I have some experience with MatLab, but I understand it is very different from C. I have Windows 10 with the newest version of Visual Studio Code (VSC) with the Run Code Extension and git extension (not sure what git does, but VSC prompted me to install). I am now familiar with the text editor, but do not know how to compile/run my code (apologies if I'm butchering the terminology, again, a newby). One friend recommended I determine the location in which the desired text file is located, type "gcc filename.c", enter, type "./a.out", and then the program should run. (Said friend has a Mac and I supposed the execution commands are different?) Regardless, I encountered "Run Code" extension on my google adventures and follow the steps I've seen online, but I am still getting the error pictured. enter image description here

I can see how this would be an especially basic question, but if anyone can offer assistance/advice, I would be extremely grateful!

Thanks, All.

Sandy

P.S. In case the image doesn't load/work for whatever reason, this is the error: "'gcc' is not recognized as an internal or external command, operable program or batch file."

Geshode
  • 3,600
  • 6
  • 18
  • 32
Sandy Spencer
  • 69
  • 1
  • 1
  • 2
  • 2
    I think your question will probably get closed, but it looks like your haven't installed the gcc compiler, or haven't configured it right. Have a look at this question. https://stackoverflow.com/questions/6394755/how-to-install-gcc-on-windows-7-machine – Brett Jul 12 '18 at 01:39
  • 1
    Also if you want to focus on the code rather than configuring dev tools (although definitely learn how to do it properly sometime) have a look at CLion https://www.jetbrains.com/clion/ – Brett Jul 12 '18 at 01:42
  • when compiling, always enable the warnings, then fix those warnings. (for `gcc`, at a minimum use: `-Wall -Wextra -Wconversion -pedantic -std=c11` ) – user3629249 Jul 12 '18 at 02:06
  • 1
    Possible duplicate of [How does one set up the Visual Studio Code compiler/debugger to GCC?](https://stackoverflow.com/questions/34057798/how-does-one-set-up-the-visual-studio-code-compiler-debugger-to-gcc) – Brett Jul 12 '18 at 02:23
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way,*** *such as to provide screenshots of a user interface."*) and [do the right thing](https://stackoverflow.com/posts/51296010/edit) (it covers answers as well). Thanks in advance. – Peter Mortensen Oct 29 '22 at 20:23

4 Answers4

4

Works perfect in Visual Code. You need the following:

  • C/C++ extension in Visual Code.
  • msys64 installed in C:\
  • Add path to msys64 bin folder in environment variable

Instructions:

https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

Important the msys64 path doesn't contain spaces so don't install it in Program Files.

You can search "Edit system environment variables" from the windows button, press button Environment Variables, and then add it as a System variable "Path". For me its located in

C:\msys64\mingw64\bin
MrGigu
  • 1,729
  • 3
  • 23
  • 37
3

Hey,,, It will work for you I believe

Blockquote

  1. First: open the link: https://www.msys2.org/
  2. Go to the installation and download the installer .. install the exe file.
  3. search mingw in windows search(windows start)
  4. there is an app named--> MSYS2 MinGW {64/32}-bit
  5. run it as administrator
  6. Found command shell ---> type: pacman -Syu
  7. Will ask you for some installation click on Y
  8. Then again go to the same app MSYS2 MinGW {64/32}-bit and run as admin
  9. and write--> pacman -Ss gcc (in shell that opend after click)
  10. after clicking there will be bunch of things and now you have to care about your windows arch.. if it is 64 bit then write---> pacman -S mingw-w64-x86_64-gcc (and if its 32 you will find something like that where 64 will replaced by 32 in bunch of commands that are showing in your shell)
  11. after executing this command gcc will be installed in your system to check write: gcc --version || g++ --version
  12. After that to install the debugger write pacman -S mingw-w64-x86_64-gdb
  13. to check write: gdb --version

**Every thing got installed in your system now find the mingW file or mysys2 file on C drive(whereever you r mingW file got saved) go the the minGW 64 || 32 accroding to your operating system there is a bin folder click on that and copy the path inside the bin folder and save it in environment variables path **

Blockquote

Enjoy vs code

Syket Das
  • 31
  • 2
1

My recommendation

You are on Windows right? So you can just install Visual Studio IDE (follow this tutorial). Which is better than vs code. This tutorial is for C++ but it works for C as well. Because C++ uses the same compiler as C but with some more things(simple explanation).

The solution for your problem

You are getting the massage 'gcc' is not recognized as an internal or external command, operable program or batch file because you do not have the gcc compiler installed on your computer. But if you want to install it, you can follow this tutorial. But I highly recommend you use Visual Studio IDE which I mentioned above.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Muzol
  • 301
  • 1
  • 11
1
  1. Type gcc --version in the command prompt to check whether the C compiler is installed in your machine.
  1. If it is installed and not recognized by VSCode then try to run VSCode from CMD by typing code in CMD.