【问题标题】:Sublime Text 2 How To Change Default Runtime Shell Command For C++?Sublime Text 2 如何更改 C++ 的默认运行时 Shell 命令?
【发布时间】:2013-08-18 16:05:32
【问题描述】:

我正在尝试通过 sublime text 2 运行 c++ 程序。我不想将 bash 添加到我的 PATH。
我想将默认 cmd 命令更改为以下内容:

./${file}

我在 c++ 包文件夹中四处寻找,但只找到了构建。

感谢您的帮助!

[编辑]
我的程序构建正确,但在运行时我得到了这个:

[Error 2] The system cannot find the file specified
[cmd:  [u'bash', u'-c', u"g++ 'C:...]
[dir:  C:\Users\...]
[path: C:/.../
[Finished]

[编辑] 根据要求,我的构建文件。

{
    "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
        }
    ]
}

【问题讨论】:

  • 请附上您的C++.sublime_build 文件。
  • 这是默认的构建文件。

标签: c++ sublimetext2


【解决方案1】:
{
    "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",

    "variants":
    [
        {
            "name": "Run",
            "cmd": ["${file_path}/${file_base_name}"]
        }
    ]
}

只需删除编译命令并仅保留可执行调用部分。但请记住,您必须在运行之前进行编译,否则将不会生成可执行文件。

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 2016-09-09
    • 2013-12-15
    • 2016-04-02
    • 1970-01-01
    • 2015-12-19
    • 2014-02-07
    相关资源
    最近更新 更多