Configure the C/C + + compilation environment of Sublime (introduction without brain)

Operation description of configuring Sublime's C/C + + compilation environment:

  • Configure compilation path
  • First, click the tool to enter the establishment system, and then enter the new establishment system. This is to establish a new compilation system
  • Then copy and save the code below to the default path
  • Save and change the name
  • Then the test is successful

premise

First, you should have your own C + + compiler. If not, you can download codeblocks or devcpp, and then find G + + Exe path.

Find G + + After the path of exe, we configure it to the user variable in the environment variable in the system variable, find the path and add the path copy. (the method of opening environment variables is: Computer - > properties - > advanced system settings - > environment variables - > user variables)

Add compilation system to sublime

tool->Build System -> New Build System

 

Overwrite the contents of the document with the following code

{ 
    "cmd": ["g++", "${file}", "-std=c++11", "-o", "${file_path}\\\\${file_base_name}", "&", "start", "cmd", "/c", "${file_path}\\\\${file_base_name} & echo. & pause"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}",
    "selector": "source.c, source.c++", "shell": true,
    "encoding":"cp936", 
 
    "variants":
    [
        {
            "name" : "Build Only",
            "cmd":["g++", "${file}", "-std=c++11", "-o", "${file_path}\\\\${file_base_name}"]
        },
        {
            "name" : "Run Only",
            "cmd" : ["start", "cmd", "/c", "${file_path}\\\\${file_base_name} & echo. & pause"]
        },
        {
            "name" : "Pipe Build and Run",
            "cmd":["g++", "${file}", "-std=c++11", "-o", "${file_path}\\\\${file_base_name}","&","${file_path}\\\\${file_base_name}", "<","${file_path}\\\\in",">","${file_path}\\\\out"]
        },
        {
            "name" : "Pipe Run Only",
            "cmd" : ["${file_base_name}", "<","in",">","out"]
        },
        {
            "name" : "Project Build & Run",
            "cmd" : ["g++", "${file_path}\\\\*.cpp", "-std=c++11", "-o", "${file_path}\\\\project", "&", "start", "cmd", "/c", "${file_path}\\\\project & echo. & pause"]
        },
        {
            "name" : "Project Build Only",
            "cmd" : ["g++", "${file_path}\\\\*.cpp", "-std=c++11", "-o", "${file_path}\\\\project"]
        },
        {
            "name" : "Project Run Only",
            "cmd" : ["start", "cmd", "/c", "${file_path}\\\\project & echo. & pause"]
        }
    ]
}

Save the name set for you. The name I set here is cpp

  • cpp: this will compile the current file and pop up a cmd command box (run this program).
  • If it is built, it is only compiled.
  • If it is run, it means only run
  • If it is build & run, it is compiled and run

shift+ctrl+B we can see the relevant instructions that pop up

  • The first cpp: this will compile the current file and pop up a cmd command box (run this program).
  • The second CPP build only: it will only compile.
  • CPP only: run the third one.
  • The fourth CPP pipe build and run: find the contents of the in file (without suffix) in the directory where the current code is located as input, and output it to the out file (also without suffix)
  • The fifth Pipe Run Only: the only difference from the above is that it will not compile. Just output.
  • The sixth project build & run is to compile all cpp files in the current directory into one file and output it as project Exe and execute the file.
  • The seventh Project Build Only: compile only, not run.
  • The eighth Project Run Only: run only without compiling.

test

  • Ctrl+N create a new text
  • Ctrl+S, save it in a path and name it a file with cpp as suffix (be sure to add. cpp as suffix, otherwise the compiling system cannot recognize which language suffix it is)
  • Write C + + program hello world
  • Press Ctrl+B to compile. After the compilation is successful, press Ctrl+shift+B to run. The running results are as follows:

 

Posted by Pinkmischief on Sat, 07 May 2022 01:29:12 +0300