Compiling C++11 Programs with Sublime Text 3

#Ubuntu #Sublime

Table of Contents

For Windows 7, you may want to read this post http://www.thefourtheye.in/2013/07/Compiling-Node.js-scripts-in-Windows-7-with-Sublime-Text-3.html\\

Today I installed Sublime Text 3's public beta on my Ubuntu 13 and the first thing I noticed is, the inability to compile C++ 11 programs. The obvious problem is, it was missing -std=c++0x parameter to g++. I tried to figure out how to edit the build parameters of Sublime. After an hour's struggle managed to figure out.\\

You need to create the following file ~/.config/sublime-text-3/Packages/C++/C++.sublime-build. The ~ refers to the home directory of the current user.
Now insert the below seen text to that file\\

 1{
 2 "cmd": ["g++", "-std=c++0x", "${file}", "-o", "${file_path}/${file_base_name}"],
 3 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
 4 "working_dir": "${file_path}",
 5 "selector": "source.c, source.c++",
 6 "variants":
 7 [
 8   {
 9     "name": "Run",
10     "cmd":["bash", "-c", "g++ -std=c++0x '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
11   }
12 ]
13}

Save this file and close it. Sublime will pick up the changes immediately.
This will take care of compiling C++ 11 programs.