Sublime text3 Configuring C / C ++ compiler environment

After installing the sublime text3, always liked to use it to see the code (the highlight color really good). It is the default condition have C / C ++, I wrote in a hello world! After the normal output, but the die was added scanf () after input. In online search, it seems no solution to this problem, you can install gcc / g ++ themselves, and then configure it to address by calling the command window. Here a simple record at the configuration process.

A. Preparations

1. Download the sublime text3, and install
2. Download MinGW (including gcc / g ++), and install

After the windows OS is installed, right-computer -> Properties -> Advanced System Settings -> Environment Variables, double-click the path, our MinGW installation path C: \ MinGW \ bin added.

II. New C compiler environment

1. Open sublime text3, selected as follows

Chinese version: Tools -> Compiler System -> New build system
in English: Tools -> Build System -> New Build System

VrY8Df.jpg

2. Enter the following code
// windows环境
{

    "working_dir": "$file_path",
    
    "cmd": "gcc -Wall \"$file_name\" -o \"$file_base_name\"",
    
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    
    "selector": "source.c",
    
    "variants":
    
    [
    
    {
    
         "name": "Run",
    
         "shell_cmd": "gcc -Wall \"$file\" -o \"$file_base_name\" && start cmd /c \"${file_path}/${file_base_name} & pause\""
    
    }
    
    ]

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

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["bash", "-c", "gcc '${file}' -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"]
        }
    ]
}
3. Save the configuration file

Save the untitled.sublime-build profile for C.sublime-build.

III. New C ++ compiler environment

Procedure C compiler and the new environment, as input variable code needs to look as follows:

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

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["cmd", "/c", "g++", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "cmd", "/c", "${file_path}/${file_base_name}"]
        },
        {
            "name": "RunInCommand",
            "cmd": ["cmd", "/c", "g++", "${file}", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & pause"]
        }
    ]
}
// mac系统
{
    "cmd": ["bash", "-c", "g++ '${file}' -std=c++11 -stdlib=libc++ -o '${file_path}/${file_base_name}'"],
        "file_regex": "^(..{FNXX==XXFN}*):([0-9]+):?([0-9]+)?:? (.*)$",
        "working_dir": "${file_path}",
        "selector": "source.c, source.c++",
        "variants":
        [
            {
              "name": "Run",
              "cmd": ["bash", "-c", "g++ '${file}' -std=c++11 -stdlib=libc++ -o '${file_path}/${file_base_name}' && open -a Terminal.app '${file_path}/${file_base_name}'"]
            }
        ]
}

Save the untitled.sublime-build configuration file for C ++. Sublime-build.

Now you can start to compile C / C ++ procedure.


Homepage:

www.codeapes.cn

Guess you like

Origin www.cnblogs.com/codeapes666/p/12093780.html