C++ 无法编译代码“启动:程序 <program_path> 不存在”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47872250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 15:42:55  来源:igfitidea点击:

Can't compile code "launch: program <program_path> does not exist "

c++visual-studiovisual-studio-code

提问by E235

I have simple console application in C++ that I succeed to compile with Visual Studio.

我有一个简单的 C++ 控制台应用程序,我成功地用 Visual Studio 编译了它。

I wanted to try Visual Studio Code so I copied the directory to the computer with Visual Studio Code installed.
I installed the C++ extension:
enter image description here

我想尝试 Visual Studio Code,所以我将目录复制到安装了 Visual Studio Code 的计算机上。
我安装了 C++ 扩展:
在此处输入图片说明

I put break point at the beginning and press F5and I received an error:

我把断点放在开头并按下F5,我收到一个错误:

launch: program 'enter program name, for example c:\Users\student1\Desktop\ConsoleApp\a.exe' does not exist.

启动:程序'输入程序名称,例如 c:\Users\student1\Desktop\ConsoleApp\a.exe' 不存在。

enter image description here

在此处输入图片说明

Of course the the program does not exist, I am compiling it in order for the code to become the program.

当然程序不存在,我编译它是为了让代码成为程序。

I followed the instruction and I went to the launch.jsonfile:

我按照说明操作,然后转到launch.json文件:

enter image description here

在此处输入图片说明

I changed the "program"value to: "${workspaceRoot}/a.exe"instead of "enter program name, for example ${workspaceRoot}/a.exe".

我将"program"值更改为: "${workspaceRoot}/a.exe"而不是"enter program name, for example ${workspaceRoot}/a.exe".

But the same problem still exist.
Any idea ?

但同样的问题仍然存在。
任何的想法 ?

回答by Manohar Reddy Poreddy

Spent 2 hours on this.

花了2个小时在这上面。

Ideally, VS Code shouldn't make so difficult for beginners

理想情况下,VS Code 不应该让初学者如此困难

VS Code can give prompts for each installation, etc. automatically, in a step by step manner, like Idea editors, so that it wont be so long procedure for beginners.

VS Code 可以像 Idea 编辑器一样,在每次安装时自动给出提示等,一步一步来,让初学者不用那么长的程序。

Sequence of steps to do(most of the things are one time):

要做的步骤顺序(大部分事情都是一次性的):

  
    one time:  
        install a C/C++ complier, add to PATH environment variable  
        install C/C++ plugin for visual studio code  
        tell visual studio code where the compiler is and what is the short cut to build and run  
           these are files under ".vscode" (see below)
    every project:  
        crate a project  
        build project  
        run project  

Detailed:

详细

One time:

一度:

Note: Point 'A' below can be skipped if you already have a compiler.

A. Install a compiler (if you don't have one already)  
    Example below, installs MinGW c++ compiler on Windows:  
    Download from here: https://sourceforge.net/p/mingw-w64/mailman/message/36103143/  
    1. For windows, I downloaded https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v5.0.3.zip  
    2. unzip mingw-w64-v5.0.3.zip  
    3. rename unzipped folder to MinGW, Move it to C:\MinGW\  
    4. verify that you have "C:\MinGW\bin\gcc.exe" director/file, otherwise make necessary change to folder  

B. Add your compiler to PATH environment variable
    1. Add "C:\MinGW\bin" to PATH > user environment variable  
    2. verify gcc command works from cmd  
        restart your cmd  
        run below command in 'cmd'  
            where gcc  
            The output should be: C:\MinGW\bin\gcc.exe  

C. Restart your visual studio code  
    1. install C/C++ plugin, as below:  
        From Menu  
             View > Extension  
        Search & Install below extension  
            C/C++  

Every project:

每个项目:

Note: You can copy paste the .vscode folder every time

注意:每次都可以复制粘贴.vscode文件夹

A. Create a below "myproj" folder & files, like below in below structure:  
    C:\myproj\myfile.cpp  
    C:\myproj\.vscode\  
    C:\myproj\.vscode\c_cpp_properties.json  
    C:\myproj\.vscode\launch.json  
    C:\myproj\.vscode\settings.json  
    C:\myproj\.vscode\tasks.json  

B. Download & overwrite the above ((5 files)), from below link

B. 从下面的链接下载并覆盖以上((5 个文件))

https://github.com/manoharreddyporeddy/my-programming-language-notes/tree/master/vscode-c%2B%2B

https://github.com/manoharreddyporeddy/my-programming-language-notes/tree/master/vscode-c%2B%2B

C. Restart your visual studio/vs code  

D. Open project in vs code & run project:

  Drag and drop "myproj" folder into visual studio code  
  BUILD PROJECT:   press "Ctrl + Shift + B" to build your myfile.exe  
  RUN PROJECT:     press "Ctrl + F5" to run your myfile.exe  

Thats all, hope that helped.

就这些,希望有所帮助。

More info: https://code.visualstudio.com/docs/languages/cpp

更多信息https: //code.visualstudio.com/docs/languages/cpp

Optional

可选的

To format C++ better

更好地格式化 C++

C++ formatting
  1. Install Clang:
     Download from: http://releases.llvm.org/download.html#5.0.2
      I have downloaded for windows 
        "Pre-Built Binaries:" > Clang for Windows (64-bit) (LLVM-6.0.0-win64.exe)  
  2. Select Add to PATH while installing.  
  3. Install vs code plugin "Clang-Format" by xaver, this wraps above exe.  
  4. Restart visual studio code.  
  Note:
   Issue:    As of June 2018, Clang does not format the newer C++17 syntax correctly.
   Solution: If so, move that code to another file/ comment & restart the vs code.

  That's all. Now press Alt+Shift+F to format (similar key combination in other OS)

回答by Vineeth Peddi

The error ".exe file does not exist" in vscode can occur because of the following reasons: 1. If the program contains white spaces 2. If there is re-declaration of variables or other kind of compilation errors

vscode 出现“.exe 文件不存在”的错误可能有以下原因: 1. 如果程序包含空格 2. 如果有重新声明变量或其他类型的编译错误

回答by Pradeep Hegde

This problem is mainly due file name , as per below table the name of the binary will be audioMatrixBin in windows folder not audioMatrixBin.exe, but we have to mention filename.exe here.

这个问题主要是由于文件名,根据下表,二进制文件的名称将是windows文件夹中的audioMatrixBin而不是audioMatrixBin.exe,但我们必须在这里提到filename.exe。

    {
        "name": "(Windows) Launch",
        "type": "cppvsdbg",
        "request": "launch",
        "program": "audioMatrixBin.exe",
        "args": ["AudioMxrMgr4Subaru.conf"],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true
    }
]

}

}