linux和Windows下用sublime text3编译运行C,C++

 

安装MinGW

1、首先安装MinGW,默认安装位置是C:\MinGW。

2、安装完成后,右键“我的电脑”->属性 ->高级->环境变量,在系统环境变量PATH里添加C:\MinGW\bin;

3、 新建LIBRARY_PATH变量,在值中加入C:\MinGW\lib。(标准库位置)

4、 新建C_INCLUDEDE_PATH变量,值设为C:\MinGW\include。

5、测试MinGW是否安装成功。Win+R,运行cmd命令行,在cmd窗口中执行g++ -v。

配置sublime

以管理员身份运行sublime text 3,进入菜单,工具-编译系统-新编译系统

Windows下输入:

 1 {
 2 "cmd": ["g++", "${file}", "-o","${file_path}/${file_base_name}"],
 3 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:?(.*)$",
 4 "working_dir": "${file_path}",
 5 "encoding":"cp936",
 6 "selector": "source.c, source.c++",
 7 "variants":
 8 [
 9 {
10 "name": "Run",
11  "shell_cmd": "g++ -Wall -std=c++11 \"$file\" -o \"$file_base_name\" && start cmd /c \"${file_path}/${file_base_name} & pause\""
12 }
13 ]
14 }

 

 

linux下输入:

假设终端为gnome-terminal
 1 {
 2 "cmd" : ["g++", "$file_name", "-o", "${file_base_name}", "-lm", "-Wall"],  
 3 "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",  
 4 "selector" : "source.c, source.c++",  
 5 "shell":false,  
 6 "working_dir" : "$file_path",  
 7   
 8 "variants":  
 9 [  
10     {  
11         "name": "Run",  
12         "cmd": ["gnome-terminal", "-e", "bash -c \"g++ '${file}' -o '${file_path}/${file_base_name}' -lm -Wall && '${file_path}/${file_base_name}' ; read -p '\nPress any key to continue...'\""]  
13     }  
14 ]  
15 }  

 

保存为 CPP.sublime-build
 

设置运行快捷键:

在首选项,快捷键设置里添加
{ 
            "keys": ["ctrl+shift+b"], 
            "command": "build", 
            "args": { "variant": "Run" }
    }

最后:

打开一个C++文件,在工具->编译系统里选择刚创建的CPP,按快捷键ctrl+shift+b即可弹出Dos窗口显示运行结果:



 

posted @ 2017-06-23 22:47  lepeCoder  阅读(5067)  评论(0编辑  收藏  举报