安裝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下輸入:
{ "cmd": ["g++", "${file}", "-o","${file_path}/${file_base_name}"], "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:?(.*)$", "working_dir": "${file_path}", "encoding":"cp936", "selector": "source.c, source.c++", "variants": [ { "name": "Run", "shell_cmd": "g++ -Wall -std=c++11 \"$file\" -o \"$file_base_name\" && start cmd /c \"${file_path}/${file_base_name} & pause\"" } ] }
linux下輸入:
- {
- "cmd" : ["g++", "$file_name", "-o", "${file_base_name}", "-lm", "-Wall"],
- "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
- "selector" : "source.c, source.c++",
- "shell":false,
- "working_dir" : "$file_path",
- "variants":
- [
- {
- "name": "Run",
- "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...'\""]
- }
- ]
- }
設置運行快捷鍵:
{
"keys": ["ctrl+shift+b"],
"command": "build",
"args": { "variant": "Run" }
}