首页 > 解决方案 > 如何在 Sublime Text 中使用 Mingw 和构建系统

问题描述

我正在使用 Sublime Text 并学习 C++。我安装了 Mingw(还添加了路径)和 Sublime Text,并添加了一个新的构建系统来获取外部输出和输入。

这是代码:

{
    "cmd" : ["g++ -std=c++14 '$file_name' -o '$file_base_name' && timeout 4s ./'$file_base_name'<input.txt>output.txt"], 
    "selector" : "source.c, source.cpp",
    "shell": true,
    "working_dir" : "$file_path"
}

Control+后B,它抛出了一个错误:

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:D:\Anand\competitive programming\input.txt: file format not recognized; treating as linker script
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe:D:\Anand\competitive programming\input.txt:1: syntax error
collect2.exe: error: ld returned 1 exit status
[Finished in 0.1s with exit code 1]
[shell_cmd: g++ "D:\Anand\competitive programming\input.txt" -o "D:\Anand\competitive programming/input" && "D:\Anand\competitive programming/input"]
[dir: D:\Anand\competitive programming]
[path: C:\MinGW\bin;C:\Program Files\Java\jdk-12.0.2\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\MinGW\bin]

Error 2:

The system cannot find the path specified.
[Finished in 0.0s with exit code 1]
[cmd: ["g++ -std=c++14 'HelloWorld.cpp' -o 'HelloWorld' && timeout 4s ./'HelloWorld'<input.txt>output.txt"]]
[dir: D:\Anand\competitive programming]
[path: C:\MinGW\bin;C:\Program Files\Java\jdk-12.0.2\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\MinGW\bin]

标签: c++outputsublimetext3user-inputmingw-w64

解决方案


您不需要在$变量周围加上单引号,也不需要./, 因为您正在运行 Windows。编辑您的构建系统以包含以下内容:

"cmd" : ["g++ -std=c++14 $file_name -o $file_base_name && timeout 4s $file_base_name < input.txt > output.txt"],

你应该准备好了。


推荐阅读