Skip to content

Instantly share code, notes, and snippets.

@clijiac
Created May 27, 2012 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clijiac/2814161 to your computer and use it in GitHub Desktop.
Save clijiac/2814161 to your computer and use it in GitHub Desktop.
Getting Sublime Text to build a C++ file.

C++ Sublime Text Build

This builds single C++ files in Sublime Text, handy for testing small things.

Works With

  • OSX (Assuming xcode installed)
  • Linux (Should work if g++ is installed)
  • Windows (Need CL working)

Thanks to adnansky for Linux Test and Shell update.

patch:add "encoding": "gb2312" to handle [Decode error - output not utf-8][Finished] http://www.sublimetext.com/forum/viewtopic.php?f=3&t=1535

{
"cmd": ["g++", "$file", "-o", "$file_base_name", "-I/usr/local/include"],
"selector": "source.c++",
"windows":
{
"cmd": ["cl", "/Fo${file_path}", "/O2", "$file"]
}
}
{
"cmd": ["g++", "$file", "-o", "$file_base_name", "-I/usr/local/include"],
"selector": "source.c++",
"windows":
{
"cmd": ["cl", "/Fo${file_path}", "/O2", "$file"]
}
}
{
"cmd": ["g++ -Wall ${file} -o ${file_base_name} && ./${file_base_name}"], "working_dir": "${file_path}",
"selector": "source.c++",
"shell": true,
"windows":
{
"cmd": ["cl", "/Fo${file_path}", "/O2", "$file"],
"selector": "source.c++",
"shell": true,
"encoding": "gb2312"
}
}
@UltCombo
Copy link

I got unknown "cl" command in Windows, and also gb2312 encoding did not fix the non-UTF-8 error. Mine had to be latin1 instead. Here's my working C++ builder working in Windows:

{
    "cmd": ["g++ -Wall ${file} -o ${file_base_name} && ${file_base_name}"], "working_dir": "${file_path}",
    "selector": "source.c++",
    "shell": true,

    "windows":
    {
        "encoding": "latin1"
    }
}

Requires MinGW's C++ compiler installed and add C:\MinGW\bin to your PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment