sublime搭建C/C++编译环境

代码一:

{ 
    "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":"utf-8", 

    "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"]
        }
    ]
}

该代码实测可以运行project的,生成project.exe
但是build一个cpp文件时要注意sublime文件夹路径、cpp文件的文件路径均不能有空格

代码二:

{
    // "shell_cmd": "make"
    "encoding": "utf-8",
    "working_dir": "$file_path",
    "shell_cmd": "g++ -Wall -std=c++11 \"$file_name\" -o \"$file_base_name\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "selector": "source.cpp",

    "variants": 
    [
        {   
            "name": "Run",
            "shell_cmd": "g++ -Wall -std=c++11  \"$file\" -o \"$file_base_name\" && \"${file_path}/${file_base_name}\""
        },
        {   
            "name": "RunInCmd",
            "shell_cmd": "g++ -Wall -std=c++11  \"$file\" -o \"$file_base_name\" && start cmd /c \"\"${file_path}/${file_base_name}\" & echo. & pause \""
        }
    ]
}

该代码实测可以运行一个cpp文件,生成filename.exe。用来写算法够用了。

参考并感谢:

https://blog.csdn.net/a19990412/article/details/82658981
https://www.cnblogs.com/whatiwhere/p/8664304.html
windows sublime text3 c++ 11环境配置注意事项

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值