Sublime Text2 built C language (c + +) compilation environment

Source: Internet
Author: User
Tags sublime text

Four steps:

    1. Download install sublime Text2 for Windows
    2. Download installation MinGW and system variable settings
    3. Sublime Building System Settings
    4. Compiling tests
One, download installs sublime Text2 for Windows: http://www.sublimetext.com/  Second, download the installation MinGW and system variable settings  This article uses the C + + compiler as gcc/g++, so you need to download the installation MinGW (: http://sourceforge.net/projects/mingw/) when the installation is complete, the user is asked to select the package to downloadSelect the package you want to download: 
, after selecting MinGW Compiler Suite, add the GNU C + + Compiler related items.   2.2 Setting environment variablesRight-click My Computer, click Properties, Advanced-environment variables.  
    1. In the environment variable path add the actual installation location of the system MinGW, such as: D:\Program Files\mingw or C:\MinGW\bin as demonstrated in this article. Add C:\MinGW\bin to Path (depending on your MinGW selection). If there are other variables in path, remember to add an English half-width semicolon. In general, the variables in PATH are very much, used between different variables;
    2. Create a new Library_path variable, if any, by adding C:\MinGW\lib to the value, which is the location of the standard library.
    3. Create a new C_includede_path variable with the value set to C:\MinGW\include.
    4. Check the variable settings: win+r input: cmd, enter on the command line: g++-V, with content input to prove that the environment variable is configured correctly. If ' g++ ' is not an internal or external command, it is not a program or batch file that can be run. Check the previous step configuration.

If the above screen shows that you have successfully installed, otherwise the environment variable setting problem. You need to modify the environment variables. Add the path to the MinGW before the environment variable that already exists. You need to restart your computer because Windows environment variables will not take effect immediately after they are modified. If you want to save trouble, do not want to restart the computer, you can directly enter the set path in the cmd C: \ \ Such environment variables will be forced to refresh.   third, Sublime Building System settingsunder Windows, to compile, run C + + code in Sublime Text 2, you need to modify or create a new C + + compilation configuration. the specific is:Sublime Text 2 Tools, build system, NEW build system
enter the following and save the file as C++bulider.sublime-bulid. {"cmd": ["g++", "${file}", "-O", "${file_path}/${file_base_name}"]," File_regex": "^ (... [^:]*]:([0-9]+):? ([0-9]+)?:? (.*)$"," Working_dir": "${file_path}"," selector": "Source.c, source.c++"," encoding": "cp936","Shell": true, "Variants":     [          {"name": "Run",//"cmd": ["cmd", "/U", "/C", "g++ ${file}-o ${file_base_name} && ${file_base_name}"]"cmd": ["Start", "${file_path}/${file_base_name}.exe"]          }     ]} 
{     "cmd" : [ "g++" "${file}" , "-std=c++11" , "-O" , "${file_path}/${file_base_name}" , "start" , "${file_path}/${file_base_name}.exe" ] //"cmd": ["make"], " File_regex": "^ (... [^:]*]:([0-9]+):? ([0-9]+)?:? (.*)$"," working_dir": " ${file_path}", " selector": "source.c, source.c++", "Shell": true, "Variants":     [        { "Name": "Run", "cmd": ["${file_path}/${file_base_name}"]         }    ]}

Then Ctrl+s, pop-up save dialog, file name changed to Mingw.sublime-build save

Then the menu bar select tools-Compile System-Choose MinGW, then you can write your own C code and then press Ctrl+b compile to see

Iv. Compiling tests  after the above steps have been built to build up the C + + compiler environment, it is possible to compile and run C + + code in sublime Text 2. : 

ctrl+b: Generatingctrl+shift+b: Run The resulting executable file is in the same directory as CPP: 
Next: Settings for templates in sublime

Or there could be a more awesome presence, directly integrated into the ST2.

123456789101112131415161718 @Echo off echo ____________________________________________ CD %~dp1 ECHO ******** ***** ***compiling**< Span class= "Crayon-o" >**** **** ***** **** ECHO wait. .IF EXIST %~N1. EXE (DEL %~N1. EXE) g+ + % ~dp1% ~nx1 -o %~N1. EXE ECHO compiling Success! Echo Running program! IF EXIST %~N1. EXE (ECHO----------- OUTPUT------------ echo. %~N1 ECHO compiling Finish Pause)

Copy the above code and save it as Compile.bat to the directory that the environment variable points to, such as your compiler, my compiler is C:Program Files (x86) Mingwbin, so I'll put it in this directory.

Then open sublime Text 2 menu bar Select tools-Compile system-compile new system

Input

123456 { "cmd": ["Compile.bat", "$file _name"], " selector": "source.c", "Shell": true, " Encoding":"GBK "}

Then Ctrl+s, pop-up save dialog, file name changed to Mingw.sublime-build save

{

"cmd" : ["gcc","${file}", "-O", "${file_path}/${file_base_name}" ] , " File_regex" :"^ (... [^:]*]:([0-9]+):? ([0-9]+)?:? (.*)$",  " working_dir": "${file_path}", " selector" : "source.c", " encoding" : "cp936", "Variants" : [  {  "Name" : "Run", "cmd" : ["cmd","/C", "gcc", "${file}", "- o", "${file_ Path}/${file_base_name} "," && ", " cmd ", "/C "," ${file_path}/${file_ Base_name} "] },  {  "Name" :"Runincommand", "cmd"    : [ "cmd" , "/C" ,  "gcc" ,  "${file}" "-O" , "${file_path}/${file_base_ Name} ", " && ", "start" ,  "cmd" ,  "/C" , "${ File_path}/${file_base_name} && pause "]&NBSP;&NBSP; }  ]  }
    • Configure shortcut keys: Run in cmd after compilation
    • Click Sublime Text 3 >> Preferences >> Key bindings-user
    • Enter the following code:
123 { "keys": ["Ctrl+alt+shift+b"], "command": "Build","args" : {"Variant": "Runincommand"} }

Execute Ctrl + B the "build" command to compile. You can see the console display as follows:

Execute Ctrl + Shift + B the "Run" command, compile and execute. You can see the console display as follows:

Execute Ctrl + Shift + Alt + B the "runincommand" command, compile and execute in CMD. Command line display

Sublime Text2 built C language (c + +) compilation environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.