简体   繁体   中英

Sublime Text 3 error : [WinError2] The system cannot find the file specified

Now I know this has been asked several times before, but all the instances of this question I could find pertained to python. However, this issue affects me even when I try to run a c++ program. Earlier today I was re-arranging some of my files (including ones that had sublime text). My sublime text started acting up and the menu was completely gone. I re-installed it and it seemed fine but whenever I tried to run a cpp (or any other) file it gave the error

[shell_cmd: g++ "C:\Users\user\Desktop\INOI22\dynamic programming\lis.cpp" -o "C:\Users\user\Desktop\INOI22\dynamic programming/lis"]
[dir: C:\Users\user\Desktop\INOI22\dynamic programming]
[path:  C:\Windows\System32; C:\Windows; C:\Users\user\Desktop\Appdata\Local;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\user\Desktop\MinGW\bin;c:\users\user\desktop\inoi22\mingw\bin; c:\windows\system32; c:\windows; c:\users\user\appdata\local]
[Finished]

I have tried reinstalling it twice since, same error every time.

I also tried messing around with my environment variables, which I think might be causing this.

Currently my %PATH% variable is set to

C:\Windows\System32; C:\Windows; 
C:\Users\user\Desktop\Appdata\Local;C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Users\user\Desktop\MinGW\bin

在此处输入图像描述

You seem to be using the C++ Single File build system that comes with Sublime Text:

{
    "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c++",

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

Unfortunately, it's Unix/Linux-centric in that the executables generated are named just by the first part of the file name. So, if you're compiling test.cpp , the executable will just be called test , with no extension. On Windows, however, executables need to have the .exe extension (generally speaking, there are exceptions) to run properly. We'll take care of this by modifying the build system.

In Sublime, select Tools → Build System → New Build System… all the way at the bottom. A template that looks like this will come up:

{
    "shell_cmd": "make"
}

Erase all of that, and add this instead:

{
    "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}.exe\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c++",

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

You'll notice that I replace the \"${file_path}/${file_base_name}\" parts with \"${file_path}/${file_base_name}.exe\" . The last thing to do is save the new build system. Hit Ctrl S (or File → Save ) and the save dialog should automatically be in your Packages/User folder, where Packages is the one opened when selecting Preferences → Browse Packages… . On Windows, it is either

  • Regular Install: C:\Users\ \AppData\Roaming\Sublime Text 3\Packages or C:\Users\ \AppData\Roaming\Sublime Text\Packages \AppData\Roaming\Sublime Text 3\Packages或C:\Users\ \AppData\Roaming\Sublime Text\Packages
  • Portable Install: \Sublime Text 3\Data\Packages \Sublime Text\Data\Packages \Sublime Text 3\Data\Packages \Sublime Text\Data\Packages

The exact path depends on version and whether or not you upgraded from Sublime Text 3. Name the file something like C++ Single File (Windows).sublime-build . It should now show up in the build system selection menu and in the Command Palette.

Now, you should be able to compile properly (assuming proper code) and run the executable without issues. Please keep in mind that Sublime does not support interactive user entry ( scanf in C, cin in C++) with regular build systems, so you'll either need to use a different custom build system or use Terminus (the recommended solution).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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