How to Run C and C++ Program in Sublime Text

In this tutorial you will learn how to run C and C++ program in sublime text on windows.

It is a very popular and widely used text editor by programmers and developers. Just follow below steps to configure sublime text to compile and run C and C++ programs. I have tested the steps in sublime text 3 but I am sure it will work for any other version also.

Also Read: Configure Notepad++ to Run C, C++ and Java Programs

How to Run C and C++ Programs in Sublime Text

How to Run C and C++ Program in Sublime Text

Here I consider that you have installed GCC compiler on your system.

Part 1: Adding Path in Environment Variables

1. Copy the path of bin folder of GCC compiler. In my case the path looks like as shown below, it may be different in your case.

C:\Program Files (x86)\CodeBlocks\MinGW\bin

2. Now right click on Computer and select Properties. Then click on Advance system settings and after that click on Environment Variables.

3. In the next window under System variables find a variable with name Path. Select it and click on Edit button.

4. In Variable value text field go to end and then type semicolon and then paste the path of bin folder that you copied. See below screenshot.

How to Run C and C++ Programs in Sublime Text

5. Finally click on all OK buttons to save the settings.

Part 2: Configuring Sublime Text

Open sublime text and go to Tools > Build System > New Build System and then paste the following lines in it.

For C:

Press ctrl+s and then save it with file name C_RUN.

For C++:

Press ctrl+s and then save it with file name CPP_RUN.

For running a program go to Tools > Build With and then select C_RUN – Run or CPP_RUN – Run according to the language you are using.

Video Tutorial

If you have any query then ask in comment section, I will try to solve it.

22 thoughts on “How to Run C and C++ Program in Sublime Text

  1. Aismita Dey

    I have followed all your steps still the output is not coming rather it is showing:” ‘gcc’ is not recognized as an internal or external command,
    operable program or batch file.
    [Finished in 0.6s]”
    Kindly help.

    Reply
    1. mohsen

      are you sure you have chosen the path which has contain gcc file ?!

      Reply
  2. KAUSHAL AGARWAL

    Sir, I have a 32 bit Windows System. After following your steps, the program successfully creates .exe file, but displays the message “This version of C:\Users\USER\Documents\codechef\try.exe is not compatible with the version of Windows you’re running. Check your computer’s system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher”
    Can u plz provide a solution

    Reply
  3. Grecil Unadkat

    After creating and compiling the file, I tried to run it but came up with no success.The message displayed was :->

    outputf.in”‘ is not recognized as an internal or external command,
    operable program or batch file.

    Reply
    1. gopal gautam

      ‘C:\Users\gopal’ is not recognized as an internal or external command,
      operable program or batch file.
      [Finished in 0.9s with exit code 1]

      i mistakely changed my default environment variable and now m getting this error

      Reply
  4. Reis

    gcc: argument to ‘-o’ is missing
    [Finished in 0.1s with exit code 1]
    [shell_cmd: gcc -o ]
    [dir: C:\Program Files\Sublime Text 3]
    [path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\AMD\ATI.ACE\Core-Static;c:\Program Files\WIDCOMM\Bluetooth Software\;c:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\MinGW\bin]

    Reply
  5. shreya kapoor

    i tried to run the program but in the console it shows

    ‘g++’ is not recognized as an internal or external command,
    operable program or batch file.
    [Finished in 0.3s with exit code 1]
    [shell_cmd: g++ “C:\Users\Shreya\trial18_01.cpp” -o “C:\Users\Shreya/trial18_01” && “C:\Users\Shreya/trial18_01”]
    [dir: C:\Users\Shreya]
    [path: “C:\Program Files\Java\jdk1.8.0_152\bin;C:\Program Files (x86)\CodeBlocks\MinGW\bin”;C:\Program Files\nodejs\;C:\Program Files\Java\jdk1.8.0_152\bin;C:\Users\Shreya\AppData\Local\Microsoft\WindowsApps;C:\Users\Shreya\AppData\Local\GitHubDesktop\bin;C:\Users\Shreya\AppData\Roaming\npm;C:\Program Files\Git\bin;]

    what should i do? kindly help

    Reply
  6. nik

    sir this is error…how can solve..
    ‘gcc’ is not recognized as an internal or external command,
    operable program or batch file.
    [Finished in 0.4s with exit code 1]
    [shell_cmd: gcc hello1.c -o hello1]
    [dir: C:\Users\sai\Documents]
    [path: C:\cygwin64\bin;C:\cygwin64\bin]

    Reply
  7. Samyukta

    gcc: error: missing filename after ‘-o’
    Please provide solution:

    gcc: fatal error: no input files
    compilation terminated.
    [Finished in 0.1s with exit code 1]
    [shell_cmd: gcc -o && /]
    [dir: C:\Program Files\Sublime Text 3]
    [path: C:\MinGW\bin;C:\Users\Samyukta\Anaconda3_new;C:\Users\Samyukta\Anaconda3_new\Library\mingw-w64\bin;C:\Users\Samyukta\Anaconda3_new\Library\usr\bin;C:\Users\Samyukta\Anaconda3_new\Library\bin;C:\Users\Samyukta\Anaconda3_new\Scripts;C:\Users\Samyukta\AppData\Local\Microsoft\WindowsApps]

    Reply
  8. Sarfaraz Hussain

    My Learning out of the above mentioned points,

    1. Download the sublime version based on your version of PC.
    2. Install minGW compiler and “Apply the changes” so that it will download else you will face gcc compiler is missing error.
    3. Copy the code for C, C++ respectively to build the system.
    4. Run the code

    Reply
  9. Nikita

    after following all steps.it is not working.
    this error comes after compiling the programme-

    C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain@16′
    collect2.exe: error: ld returned 1 exit status
    [Finished in 0.8s]

    what is the solution..plz explain

    Reply
  10. Tanya

    g++: error: : No such file or directory
    g++: fatal error: no input files
    compilation terminated.
    [Finished in 0.5s with exit code 1]
    [shell_cmd: g++ “” -o “/” && “/”]
    [dir: C:\Users\Lenovo\Downloads\Sublime Text Build 3207]
    [path: “C:\Program Files (x86)\Intel\iCLS Client\;C:\TDM-GCC-64\bin”;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\Lenovo\AppData\Local\Microsoft\WindowsApps;;C:\TDM-GCC-64\bin]

    Reply
  11. akram

    sir
    i did everythin but it does not work
    it show

    ‘javac’ is not recognized as an internal or external command,
    operable program or batch file.
    [Finished in 0.0s]

    Reply
  12. Ruchi Sharma

    sir,
    I want say that i am running c programm then successfully run but c++ program is not run
    why?

    Reply
  13. Caligula Infinity

    That part when you said to edit the path in computer properties and paste the address of bin. In my case, I’ve been using subime for python, and now when I’m doing your part, i.e, editing the path, that is already of python and I want to run C on sublime. Please help

    Reply
    1. Mark Jordan

      Hi Caligua Infinity, I hope you’ve been able to figure the issue out, if you haven’t:

      If you’re logged in with an administrative account,
      1. Search for “Environment Variables” and click on the relevant result in your start menu.
      2. A Menu should open up and you should be able to click on “Path” and Edit (It opens up a window in Windows 10 – this should make it easier.
      3. Select “New” and paste the path to your C compiler bin.
      4. Save and return to Sublime text. Restart it (sometimes before proceeding to enable it process the changes).
      5. As at the time of writing this, Sublime automates the process of searching and picking the bin file for your preferred language.
      6. If it doesn’t, follow the processes above and create a new build.
      7. Set the parameters to enable it search for the bin file.
      8. Save settings and restart.
      9. I hope it works!

      Reply
  14. Jayanth PSY

    when i try to run my c program,

    ‘C:\Users\JAYANTH’ is not recognized as an internal or external command,
    operable program or batch file.
    [Finished in 0.5s with exit code 1]
    [shell_cmd: gcc hi.c -o hi && C:\Users\JAYANTH PSY\Desktop\studs\pds lab\commando/hi]
    [dir: C:\Users\JAYANTH PSY\Desktop\studs\pds lab\commando]
    [path: C:\windows;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NGX;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\MinGW\bin;C:\Users\JAYANTH PSY\AppData\Local\Microsoft\WindowsApps;]

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *