Explore with  

Building & Running C++ in Sublime Text (Windows)

My addiction towards Sublime Text desists me from laying my hands on any other code/text editors… Compiling, Building and Running C++ was one of the biggest reason to use other code editors like CodeBlocks, etc..

For C++ only, I started using CodeBlocks. But after some time I realized that its interface is so boring and was far behind Sublime even though it has a built-in compiler, its interface was so dull.

So I started searching and google-ing to find out is there a way by which we can compile C++ programs in Sublime. After an hour or so I found the solution which is not so hard.

So lets get started …

Installing MinGW (C++ Compiler)

  • First, download the latest MinGW from here.
  • Install it in the C:/MinGW (recommended) drive and then press Finish to continue.
  • Now locate your bin folder. According to the steps it should be here: C:/MinGW/bin
  • Now add it to the PATH evironment variables.
  • To do that, go to : Start >> Control Panel >> System >> Advanced >> Environment Variables
  • Click on New under User Variables.
  • Now type MinGW in the Variable name field and the Location of your bin folder in the Variable value field and press OK
  • THATS IT ! You have successfully installed MinGW.

Now its time to set it up with Sublime.

Setting up with Sublime

  • NOTE: Save all your .cpp files in the bin directory only without putting in a folder. Your files should not be in a folder there path sould be like this: C:/MinGW/bin/YourFileName.cpp
  • Now open Sublime.
  • Go to: Tools >> Build System and make sure that C++ is selected.

Done …!

FINALLY DONE! You have finally completed the tutorial.

Now get going Sublimers. Press Ctrl + B to Build and Ctrl + Shift + B to Run.

About the Author

Ishaan Rawat is a Web Designer and Developer living in Jaipur. He loves to code and learn programming. He can be found solving public issues and problems on Experts-Exchange or Wordpress Forums. He is presently a Guru in Experts-Exchange having more than 150,000 points in HTML, CSS. You can find him on , , and .

Comments / Remarks
Tobias on August 22, 2013 commented: Nice tutorial and all, but.. Saving all new .cpp files in the bin directory of MinGW is really not cool. Do you know of a way to save it wherever I want?
Ishaan Rawat on August 24, 2013 commented: I am on that only but till now I have not found any solution for that. Apologize for the inconvenience.
witwiki on September 27, 2013 commented: This didn't work for me. I get this error when I put "C:\MinGW\bin" in my Environment Variables under User Variables as a "New" variable. I also tried putting "C:\MinGW\bin" under the "PATH" "Variable Name" right at the end. Any help appreciated.
Ishaan Rawat on September 27, 2013 commented: Have you installed MinGW in the correct place and followed the steps carefully...???
Amstramgram on December 13, 2013 commented: Step 1 : Installe MinGW Step 2 : Créer un fichier C++.sublime-build, enregistrer ça dans user. { "cmd": ["g++", "${file}", "-o", "VotreCheminVersMinGW/bin/${file_base_name}"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "VotreCheminVersMinGW/bin", "selector": "source.c, source.c++", "variants": [ { "name": "Run", "cmd": ["CVotreCheminVersMinGW/bin/${file_base_name}.exe"] } ] }
Rahul on December 25, 2013 commented: Thanks for your great tutorial. I have to ask one thing, is it possible to launch "mypro.exe" automatically after successfully building of the mypro.cpp file. If possible, How? and if not Why? Thanks in advance. Waiting for your response.
Rohit Chakravarthi on May 2, 2014 commented: The build system of C++ in sublime which is there by default does not take into account the "c++ -std" thing. it says 'emplace member not found'. I guess we have to alter the build system. But how do you do that?
Add your comment