简体   繁体   English

在Sublime Text 3上构建C ++文件没有结束

[英]Building C++ files on Sublime Text 3 not ending

As you know, you can build a file in Sublime either: 如您所知,您可以在Sublime中构建文件:

1) Through Ctrl+Shift+B (Build With) -> C++ Single File 1)通过Ctrl + Shift + B(Build With)-> C ++单个文件

2) Through Ctrl+Shift+B (Build With) -> C++ Single File - Run 2)通过Ctrl + Shift + B(构建方式)-> C ++单个文件-运行

Via the first option I have no problems: file compiles, Sublime confirms, and I don't experience any problems. 通过第一个选项,我没有问题:文件编译,Sublime确认,并且我没有遇到任何问题。

If I do it the second way, Sublime can't stop the build process. 如果我采用第二种方法,Sublime无法停止构建过程。 Right after I click build, a process '(file_name).exe(32 bit)' on Task Manager is created, but the .exe program never runs automatically from Sublime (I have to run it myself), and Sublime never confirms the build. 单击生成后,立即在任务管理器上创建了一个进程'(file_name).exe(32位)' ,但是.exe程序从未从Sublime自动运行(我必须自己运行),并且Sublime从不确认生成。

How can I fix this? 我怎样才能解决这个问题?

Here is the sublime-build file: 这是sublime-build文件:

{
    "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}\""
        }
    ]
}

Try editing the `"Variants" section like so: 尝试像这样编辑“变量”部分:

"variants":
[
    {
        "name": "Run",
        "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k \"${file_path}/${file_base_name}\""
    }
]

This will start a separate instance of cmd.exe and run your newly-built executable within it. 这将启动cmd.exe的单独实例,并在其中运行新建的可执行文件。 One possible reason your build isn't succeeding is the .exe may be waiting for input, which Sublime's console doesn't allow (it's not a true terminal). 您的构建未成功的一个可能原因是.exe可能正在等待输入,而Sublime的控制台不允许该输入(这不是真正的终端)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM