【问题标题】:sublime text 2 can't run my c program?sublime text 2 无法运行我的 c 程序?
【发布时间】:2014-02-21 00:23:34
【问题描述】:

我使用的是 Windows 7,我已经添加了

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

到我的 c.sublime-build 虽然它可以构建我的程序,但运行选项消失了。所以我看不到我的简单 hello world 程序的输出。

【问题讨论】:

  • 正确缩进和结构化摘录是确保人们真正阅读它们的好方法 :) 这次为您解决了这个问题

标签: c compiler-construction editor sublimetext


【解决方案1】:

您需要为将执行程序的Run 选项添加variant。这是我的 g++.sublime-build 的样子

{
    "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 选项构建然后运行程序,如果您只希望它运行可执行文件,请去掉命令的前半部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    相关资源
    最近更新 更多