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++ 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.
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:
{ "shell_cmd" : "gcc $file_name -o ${file_base_name}", "working_dir" : "$file_path", "variants": [ { "name": "Run", "shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}" } ] }
Press ctrl+s and then save it with file name C_RUN.
For C++:
{ "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"", "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++", "variants": [ { "name": "Run", "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\"" } ] }
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.
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.
try restarting
are you sure you have chosen the path which has contain gcc file ?!
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
My sublime was working fine but suddenly I’m Facing the same issue. Did you manage to solve it?
When i restart my pc then it’s compiling fine but after some time ,error “unsupported 16 bit application” oocurs.
it already told you what to do!!!
you’re a programmer??
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.
‘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
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]
Keep up bro.
i found it…..
‘C:\Users\saurabh’ is not recognized as an internal or external command,
operable program or batch file.
[Finished in 4.7s with exit code 1]
[shell_cmd: gcc f1.c -o f1 && C:\Users\saurabh rajput\Desktop/f1]
[dir: C:\Users\saurabh rajput\Desktop]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\brackets\Brackets\command;C:\Program Files\nodejs\;C:\MinGW\bin;C:\Python\Python38\Scripts\;C:\Python\Python38\;C:\Users\saurabh rajput\AppData\Local\Microsoft\WindowsApps;C:\Users\saurabh rajput\AppData\Roaming\npm;C:\Program Files\JetBrains\PyCharm 2020.1.1\bin;;C:\Users\saurabh rajput\AppData\Local\Programs\Microsoft VS Code\bin]
i am getting permission denied.
Thanks!!!
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
restart sublime
I’ve done this several times and this persists. I’m just going to run it through the terminal, it’s not worth all this. g++ works fine there.
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]
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]
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
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
Thanks, Men!
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]
Hi,
Ich have the same error message ridiculing me.
Just wonder, did you manage to solve the problem in the meantime?
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]
sir,
I want say that i am running c programm then successfully run but c++ program is not run
why?
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
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!
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;]
{
“shell_cmd” : “gcc *.c -o ${file_base_name}”,
“working_dir” : “$file_path”,
“variants”:
[
{
“name”: “Run”,
“shell_cmd”: “gcc *.c -o ${file_base_name} && ${file_path}/${file_base_name}”
}
]
}
‘g++’ is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.1s with exit code 1]
[shell_cmd: g++ “C:\Users\win7\AppData\Roaming\Sublime Text 3\Packages\User\CPP_RUN.sublime-build” -o “C:\Users\win7\AppData\Roaming\Sublime Text 3\Packages\User/CPP_RUN”]
[dir: C:\Users\win7\AppData\Roaming\Sublime Text 3\Packages\User]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32C:\Program Files\Sublime Text 3\Packages\Wbem;C:\Windows\Program Files\WindowsPowerShell\v1.0\;C:\Program Files\Sublime Text 3\Packages]
how did you solved this error. Im having the same problem.
Is there any way to use any other program instead of using cmd?
Does the location where we save C_RUN matters?
Can we save it anywhere we like?
Seems like most people are getting the same error. I am another one of those people.
‘C:\Users\chris\AppData\Roaming\Sublime’ is not recognized as an internal or external command,
operable program or batch file.
Why is everything so difficult?
I too had the same issue .. can you explain how to rectify that please?
Still getting those same errors…
‘C:\Users\Theodor’ is not recognized as an internal or external command,
operable program or batch file.
The program builds and I can execute it manually, but it doesn’t run by itself.
For all of the MacOS users trying to do this, I found it easier to change the script for the C_RUN file to the code pasted below. This will build, open up a new terminal window, and run your program in that terminal window all with “Shift + Command + B” shortcut. To quickly exit the terminal back to Sublime, use the “Command + q” shortcut. This makes for quickly testing and iterating C programs within Sublime Text. Thanks for the original article on this Neeraj!
{
“shell_cmd” : “gcc $file_name -o ${file_base_name}”,
“working_dir” : “$file_path”,
“variants”:
[
{
“name”: “Run”,
“shell_cmd”: “gcc $file_name -o ${file_base_name} && open -a Terminal ${file_path}/${file_base_name}”,
“working_dir”: “${project_path}”
}
]
}
thaaanks