构建时没有问题,最后一行的消息显示“构建完成”...但是当我尝试运行它时,出现此消息:
[Error 2] The system cannot find the file specified
[cmd: [u'bash', u'-c', u"g++ 'D:\\Apps\\hello.c' -o 'D:\\Apps/hello' && 'D:\\Apps/hello'"]]
[dir: D:\Apps]
[path: C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Broadcom\Broadcom 802.11\Driver;C:\Program Files\Calibre2\;C:\Program Files (x86)\Vodafone\Vodafone Mobile Broadband\Optimization Client\;C:\Python27;C:\Python27\Scripts;C:\Program Files (x86)\CodeBlocks\MinGW\bin\;D:\Apps]
[Finished]
而且我还是 Sublime Text 2 的新手。
最佳答案
在 Sublime 中创建一个包含以下内容的新文件:
{
"cmd": ["mingw32-g++.exe", "-o", "$file_base_name", "$file"],
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
在第 2 行,将 mingw32-g++.exe
的名称更改为您系统上的任何 g++
- 可能只是 g++.exe
。将文件保存在 Packages
文件夹的 User
子目录中(应该在 %APPDATA%\Sublime Text 2
中)作为 new_g++ .sublime-build
.当您选择此构建系统作为默认构建系统时(Tools -> Build System -> new_g++
),按 CtrlB 将编译您的程序,并且然后按 CtrlShiftB 将执行它。 start
是开始运行一个独立进程的命令,cmd
是cmd.exe
的缩写,Windows命令行程序, >/k
选项在您的程序退出后使结果窗口保持打开状态,以便您可以查看其输出、运行其他命令或您有什么。
关于c - 如何在 Sublime Text 2 中运行一个 c 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20321216/