Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Aug 14, 2013

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
You can’t perform that action at this time.