配置编译系统
新建编译系统并粘贴入以下命令,保存为 G++.sublime-build
或其他你喜欢的名称。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| { "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" -Wall", "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path}", "selector": "source.c, source.c++", "variants": [ { "name": "compile", "shell_cmd": "g++ \"${file}\" -o \"/tmp/${file_base_name}\" -Wall -O2 && echo 'Compile finished.'" }, { "name": "run", "shell_cmd": "'/tmp/${file_base_name}' && echo '=============\nRun finished.'" }, { "name": "compile & run", "shell_cmd": "g++ \"${file}\" -o \"/tmp/${file_base_name}\" -Wall -O2 && /tmp/${file_base_name} && echo '=============\nComplie & run finished.'" } ] }
|
配置编译运行快捷键
把以下代码粘贴到你的快捷键配置文件中,表示 F9
编译, F10
运行, F11
编译并运行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| { "keys": ["f9"], "command": "build", "args": { "variant": "compile" } }, { "keys": ["f10"], "command": "build", "args": { "variant": "run" } }, { "keys": ["f11"], "command": "build", "args": { "variant": "compile & run" } }
|
其他注意事项
Mac OS 下默认用 Clang 编译 G++ 代码。因此不支持使用万能头文件(bits/stdc++.h
),解决方案:
手动复制 bits/stdc++.h
文件到对应目录中
手动安装 g++4.9
并把上面编译命令中的 g++
替换为 g++-4.9