我正在使用Windows7,我已经添加了

{
    "cmd" : ["gcc", "$file_name", "-o", "${file_base_name}.exe", "-lm", "-Wall"],
    "selector" : "source.c",
    "shell":true,
    "working_dir" : "$file_path"
}

对于我的c.sublime-build,尽管它可以构建我的程序,但是run选项消失了。所以我看不到简单的hello world程序的输出。

最佳答案

您需要为执行程序的Run选项添加variant。这是我的g++.sublime构建的外观

{
    "shell_cmd": "g++ \"${file}\" -O3 -std=c++11 -pedantic -Wall -Wextra -Wconversion -o \"${file_path}/${file_base_name}\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
        {
            "name": "Run",
            "shell_cmd": "g++ \"${file}\" -O3 -std=c++11 -pedantic -Wall -Wextra -Wconversion -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
        }
    ]
}

我的Run选项生成并运行程序,如果您只想让它运行可执行文件,请去掉命令的前半部分。

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

10-11 22:42
查看更多