Skip to content

Instantly share code, notes, and snippets.

@clijiac
Created May 27, 2012 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clijiac/2814517 to your computer and use it in GitHub Desktop.
Save clijiac/2814517 to your computer and use it in GitHub Desktop.
A simple C++ builder for Sublime Text 2. (use cl)
:: Assumptions:
:: - Sublime Text has set the working directory and both the source and executable files
:: are in that directory
:: - The script is only capable of handling simple C# apps that do not reference 3rd-party
:: libraries
:: Inputs from Sublime Text
:: %1 - The full path and filename of the source file to build
:: %2 - The name of the executable file
@SET SRC_FILE="%1"
@SET EXE_NAME="%2"
:: Set up build environment. Change this as necessary depending on the version
:: of Visual Studio you wish to use.
@CALL "vsvars32.bat"
cl /O2 /GL /W3 /TP /EHsc %SRC_FILE%
@IF errorlevel 1 GOTO end
del *.obj
:: Execute compiled binary if build was successful.
@ECHO.
@ECHO Executing %EXE_NAME%:
@ECHO.
@%EXE_NAME%
::end
{
"cmd": ["g++ -Wall ${file} -o ${file_base_name} && ./${file_base_name}"], "working_dir": "${file_path}",
"selector": "source.c++",
"shell": true,
"windows":
{
"cmd": ["$packages\\User\\buildC.bat", "$file", "${file/\\.cpp/\\.exe/}"],
"working_dir": "${file_path}",
"file_regex": "^(...*?)[(]([0-9]*),([0-9]*)[)]",
"shell": true,
"encoding": "gb2312"
}
}
@clijiac
Copy link
Author

clijiac commented Jul 24, 2014

For mingw use

{
    "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "shell": true,

    "variants":
    [
        {
            "name": "Run",
            "shell": true,
            "cmd": ["g++", "$file", "-o", "$file_base_name", "&&", "$file_path/$file_base_name"]
        }
    ]
    , "windows":
    {

        "encoding": "gb2312"
    }
}

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