繁体   English   中英

Sublime text 在为 C++ 14 创建构建系统时出错

[英]Sublime text gives error on creating a build system for c++ 14

我在我的 Sublime Text 3 中为 C++ 14 创建了一个新的构建系统,并粘贴了以下代码并将其保存为 C++ 14。

{
 "cmd":["bash", "-c", "g++ -std=c++14 -Wall '${file}' -o '${file_path}/${file_base_name}' && '${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++ -std=c++14 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
   }
 ]
}

但是每当我选择这个版本(保存的C++ 14 )来运行我的 C++ 程序时,我的 Sublime Text 就会出现以下错误:

[WinError 2] The system cannot find the file specified
[cmd: ['bash', '-c', "g++ -std=c++14 -Wall 'C:\\Users\\ragha\\Desktop\\All_Folders\\sublime_cpp\\_code.cpp' -o 'C:\\Users\\ragha\\Desktop\\All_Folders\\sublime_cpp/_code' && 'C:\\Users\\ragha\\Desktop\\All_Folders\\sublime_cpp/_code'"]]
[dir: C:\Users\ragha\Desktop\All_Folders\sublime_cpp]
[path: C:\Python38\Scripts\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Calibre2\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Java\jdk-14.0.1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Python38\python.exe;C:\Python38;C:\MinGW\bin;C:\Users\ragha\AppData\Local\Microsoft\WindowsApps;C:\src\flutter\bin;C:\MinGW\bin;]
[Finished]

注意 - 我已经安装了 MinGW C++ 安装程序。 我已将 C:/MinGw/bin 添加到Global Variables as well as System Variables的路径中。 当我使用C++ single file构建运行它时,我的 C++ 程序运行良好。 我的系统中没有任何 WSL。

如何解决问题。

请帮忙!

这是一个可以尝试的新构建系统:

{
    "shell_cmd": "bash -c \"g++ -std=c++14 -Wall '${file}' -o '${file_path}/${file_base_name}.exe' && '${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", "'${file_path}/${file_base_name}'"]
    }]
}

"shell_cmd"将其所有参数作为一个字符串,因此我根据需要将所有参数与转义双引号组合在一起,并进行了一些调整以使其运行,至少对我而言是这样。

我还将您的Run部分更改为仅运行已编译的二进制文件。 在您的原始版本中,您在运行之前再次编译。 您会注意到我在这里使用了"cmd"函数,其中的参数是逗号分隔的字符串数组。

请注意,这个构建系统仍然在 Sublime 的控制台中运行二进制文件,所以你不能做一些事情,比如来自用户的请求输入。 但是,如果您想在单独的命令提示符下运行程序以接受用户输入,例如,请使用以下构建系统:

{
    "shell_cmd": "g++ -std=c++14 -Wall ${file} -o ${file_path}/${file_base_name}.exe && start cmd /k ${file_path}/${file_base_name}",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "shell": true,

    "variants": [
    {
        "name": "Run",
        "cmd": ["start", "cmd", "/k", "$file_base_name"],
        "working_dir": "${file_path}",
        "shell": true,

    }]
}

编辑

如果你只想Sublime 中编译和运行你的程序,这应该可行:

{
    "shell_cmd": "g++ -std=c++14 -Wall ${file} -o ${file_path}/${file_base_name}.exe && ${file_path}/${file_base_name}",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "shell": true,

    "variants": [
    {
        "name": "Run",
        "cmd": ["$file_base_name"],
        "working_dir": "${file_path}",
        "shell": true,

    }]
}

暂无
暂无

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

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