如何解决Sublime文本在为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","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 ++安装器。我在两个Global Variables as well as System Variables
中的路径中都添加了C:/ MinGw / bin。当我使用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}","shell": true,"cmd": ["start","cmd","/k","$file_base_name"],}]
}
编辑
如果您只想在Sublime中编译并运行程序 ,则该方法应该有效:
{
"shell_cmd": "g++ -std=c++14 -Wall ${file} -o ${file_path}/${file_base_name}.exe && ${file_path}/${file_base_name}","cmd": ["$file_base_name"],}]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。