c - 如何在 Sublime Text 2 中运行一个 c 程序?

标签 c sublimetext2

构建时没有问题,最后一行的消息显示“构建完成”...但是当我尝试运行它时,出现此消息:

[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是开始运行一个独立进程的命令,cmdcmd.exe的缩写,Windows命令行程序, >/k 选项在您的程序退出后使结果窗口保持打开状态,以便您可以查看其输出、运行其他命令或您有什么。

关于c - 如何在 Sublime Text 2 中运行一个 c 程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20321216/

相关文章:

c - 在 C 中使用结构时的内存分配

c - 与 Ubuntu 相比,我的 C 代码在 Mac 中运行缓慢

c - 重复直到用户按下 Enter 键

sublimetext2 - Mac OSX 上 sublime text 2 的日志文件的位置是什么

sublimetext2 - Sublime Text 2 dart 构建错误

分割pcap文件的C程序

c - 如何在c中使用指针获取回文?

autocomplete - 如何防止 Sublime Text 2 吞掉右括号、引号和圆括号?

text - 在 Sublime Text 2 中突出显示 nbsp 字符?

python - 请在设置中定义 lint.py 的完整路径