【问题标题】:Sublime Text 3 shows "No Build System" on the status bar when I try to compile my C++ code. Why?当我尝试编译我的 C++ 代码时,Sublime Text 3 在状态栏上显示“No Build System”。为什么?
【发布时间】:2019-07-29 06:41:53
【问题描述】:

当我尝试构建它时,它会显示此错误。只有在我的自定义构建系统文件中输入以下代码后才会发生这种情况:

只有在输入代码的“Run in CMD”部分后才会发生

{
"shell_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",
        "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
    }
    {
        "name": "Run in CMD",
        "shell_cmd": "start \"$file_base_name\" call $file_base_name"
    }
 ]
}

该程序的用途是添加一个变体,它在CMD中打开已编译的程序,而不是在Sublime Text 3中打开集成终端。

【问题讨论】:

    标签: c++ sublimetext3


    【解决方案1】:

    显示No build system 消息的最终原因是当您尝试运行构建时,Sublime 不知道它应该应用什么构建系统。

    当您将构建设置为 Automatic 但当前文件属于 Sublime 无法确定构建系统的类型时,可能会发生这种情况,但它也可能发生在它将使用的构建文件(通过Automatic 或被明确告知)以某种方式被破坏。

    在你的情况下,这就是原因; sublime-build 文件第 12 行的两个变体之间缺少 ,。因此,该文件不是有效的 JSON,构建文件被视为不存在,并且您会收到有关没有构建系统的消息。

    添加逗号应该可以解决您的问题:

    {
    "shell_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",
            "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
        }
    // These two variants are part of a list; they need to be separated
    // with a comma
        {
            "name": "Run in CMD",
            "shell_cmd": "start \"$file_base_name\" call $file_base_name"
        }
     ]
    }
    

    【讨论】:

    • 那行有个逗号
    • 没有,变体键中的两个变体对象只是两个相邻的对象,但它们是variants 列表的一部分。我编辑了问题以概述错误位置。我提到的行号不准确;当我将它粘贴到 linter 中时,它会重新格式化它。对此感到抱歉。
    猜你喜欢
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2014-04-18
    相关资源
    最近更新 更多