c++buildsublimetext2

How to build and run c++ programs in Sublime Text 2, Windows 8?


I installed Codeblocks with mingw, chose default compiler, and could build and run a simple hello program without errors.

I installed Sublime Text 2, copy pasted the same hello world program:

// my first program in C++
#include <iostream>

using namespace std;

int main ()
{
    cout << "Hello World!";
    return 0;
}

Upon building, I get the error message:

[Error 2] The system cannot find the file specified
[cmd:  [u'bash', u'-c', u"g++ '' -o '/' && '/'"]]
[dir:  C:\Windows\system32]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\]
[Finished]

What do I need to do in order to build and run a simple program using Sublime Text 2?


Solution

  • First, make sure you save the file you're working on, wherever on your drive, before building and running.

    Sublime Text 2 needs g++, bash, etc in order to compile. These packages need to be installed on your computer, as per the instructions on this page:

    http://mjiang.com/mec/cs244/files/Installing%20c++_g++_on_Windows.pdf