Home Download Buy Blog Forum Support

fail to run c++ file in sublime text 2

fail to run c++ file in sublime text 2

Postby alogedro on Thu Dec 05, 2013 10:17 pm

Hello, I was try to run a simple c++ code in sublime. when I hit "build", it said "finished in 0.7s"; however, when I clicked on the run button, it returned
"[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"g++ 'C:\\Users\\Danny Wang\\Desktop\\Study\\Programming\\Internet C++ problems\\1.1.cpp' -o 'C:\\Users\\Danny Wang\\Desktop\\Study\\Programming\\Internet C++ problems/1.1' && 'C:\\Users\\Danny Wang\\Desktop\\Study\\Programming\\Internet C++ problems/1.1'"]]
[dir: C:\Users\Danny Wang\Desktop\Study\Programming\Internet C++ problems]
[path: C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Autodesk\Backburner\;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program Files\Perforce;C:\Program Files\Perforce\Server]

what should I do now?
Posts: 2
Joined: Thu Dec 05, 2013 10:03 pm

Re: fail to run c++ file in sublime text 2

Postby MattDMo on Sat Dec 07, 2013 12:40 am

I just answered a very similar question on StackOverflow. Here it is for posterity:

Create a new file in Sublime with the following content:
Code: Select all
    "cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],

    "variants": [

            "cmd": ["start", "cmd", "/k", "$file_base_name"],
            "shell": true,
            "name": "Run"

On the 2nd line, change the name of mingw32-g++.exe to whatever g++ is on your system - possibly just g++.exe. Save the file in the User subdirectory of your Packages folder (which should be in %APPDATA%\Sublime Text 2) as new_g++.sublime-build. When you select this build system as your default (Tools -> Build System -> new_g++), hitting Ctrl-B will compile your program, and then hitting Ctrl-Shift-B will execute it. start is the command to start running a separate process, cmd is short for cmd.exe, the Windows command line program, and the /k option keeps the resulting window open after your program exits so you can see its output, run additional commands, or what have you.

The reason the build command failed is because it is trying to call bash, which is not installed by default on Windows systems. This bug has been fixed in Sublime Text 3.
Python Improved - a better syntax definition for Python 2 and 3.
Neon Color Scheme - a bright-on-black color scheme aiming to make as many languages as possible look as good as possible.
Posts: 44
Joined: Thu Jan 17, 2013 3:15 am
Location: near Boston

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 8 guests