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

17

49

I have simple console application in C++ that I succeed to compile with 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

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

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

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.json file:

enter image description here

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

But the same problem still exist.
Any idea ?

Montes answered 18/12, 2017 at 16:9 Comment(5)
Is another instance of the program currently open?Tie
@JakeFreeman No.Montes
Did you able to run the program using the terminal?Intoxicated
@Intoxicated I can't run the program because it is not created yet. I am trying to compile it and then run it but I is not compiling. I am searching for other compiler.Montes
Do you have any compilation errors?Intoxicated
E
66

Spent 2 hours on this.

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

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.

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


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

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

Optional

To format C++ better


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)

Eggett answered 2/6, 2018 at 14:49 Comment(8)
In order to debug with VSCode i have to download another debugger? No thanks. The job of the addon was to come with everything needed.Alger
It's time-consuming, true. VS Code is a generic editor though so slowly things get better.Eggett
Hi there, I've found the right path to the compiler binary, but I just wanted to get clarification. Do you place the path value in the windows environment variables or in vscode? I'm using chocolatey which is already hooked up to git inside vscode. I can run gcc commands, so yeah would be good to hear where to place the variables...Noncommittal
I reread my answer above, i think it is windows environment variablesEggett
sadly, this bloated answer may well be correct. it is a horrendous process getting c++ working in vs code... 5 years later from this post, and it is no better.Matronly
For my simple programming I prefer to just run gcc from the terminal in vscode. Though I've come to like emacs in a linux environment, if only I could remember all the key combosPectase
At this point, why even use vs code? Why not just run it in the terminal and use a normal text editor? If they're gonna make you go through this much trouble every single time.Illuminometer
In the defense of vscode, it is c++ which is a mess and a hell to get it anywhere beginner friendly, in particular when it comes to toolchains...Morris
F
7

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.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "audioMatrixBin.exe",
            "args": ["AudioMxrMgr4Subaru.conf"],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true
        }
    ]
}
Floodlight answered 3/5, 2018 at 10:44 Comment(1)
Simply this is the answer, program should match the code file name, saved my dayLocust
E
5

The error ".exe file does not exist" in vscode can occur because of the following reasons:

  1. If the file name contains white spaces
  2. If there is re-declaration of variables or other kind of compilation errors
Edison answered 13/5, 2020 at 12:5 Comment(0)
W
3

Make sure your "program" and "cwd" properties are actually correct. Check the path it tells you and compare with the path you want them to be.

Wendiewendin answered 29/8, 2020 at 5:9 Comment(0)
P
2
  1. Go to launch.json(we've encounter problem with .json file that's why we're here)

  2. Change 'cwd' & 'miDebuggerPath' where your 'gdb' is(mine is default).

    • "cwd": "C:\\MinGw\\bin",

    • "miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"

      (you can copy-paste if yours is default too).

  3. Now run with 'gcc.exe-Build and debug active file'

    (run your file with this option, this should run)

Predict answered 8/4, 2021 at 3:21 Comment(2)
how to run with gcc.exe-buildTriglyph
For windows: ctrl-shift-b . Else Run-Build-Task in Terminal menu.Phonate
U
2

Nuke everything and use the build active file tasks:

  1. Delete all files within the .vscode folder.
  2. Select Terminal > Configure Tasks
  3. Select appropriate system task (i.e. for Mac, C/C++: clang build active file).
  4. Open .vscode/tasks.json
  5. Configure C++ language standard by specifying the std flag (i.e. "-std=c++17") at the top of the args array.
Unerring answered 13/9, 2022 at 18:33 Comment(1)
This was close to solving my issue. I'm new to C/C++ and I am following this doc: code.visualstudio.com/docs/cpp/config-clang-mac. I had to edit tasks.json from "command": "/usr/bin/clang", to this: "command": "/usr/bin/clang++",Arakawa
L
1

It seems that launch.json file needs to have the correct configs.

please check the configurations as per the below link, if you are using VS build tools https://code.visualstudio.com/docs/cpp/config-msvc

or delete the launch.json file, gotoRun > Add Configuration... and then choose C++ (Windows), Choose cl.exe build and debug active file. Check the new name in launch.json and try again.

Lehrer answered 21/10, 2020 at 5:16 Comment(0)
B
1

This video explain it very well how to setup vscode for c, I did it on Ubuntu. https://www.youtube.com/watch?v=9pjBseGfEPU

Then I use this reference to setup c++, https://code.visualstudio.com/docs/cpp/config-linux

I just had to replace "command": "/usr/bin/gcc" with "command": "/usr/bin/g++", from the example on the video. and you can update the label on both tasks and launch if you want it.

this is how my c++ setup ended up. tasks.json for c++

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            // "command": for classic c, "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/bin/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "isDefault": true,
                "kind": "build"
            }
        }
    ]
}

launch.json for c++{

    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/bin/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file"
        }
    ]
}
Bataan answered 2/9, 2021 at 19:18 Comment(0)
L
1

To resolve this proble one has to make sure three things are in order:

  1. You have successfully downloaded and install the gcc (compiler) and gdb (debugger). To check this you should be able to type
gcc --version 

and

gdb --version

and get the correct results

  1. Once done with this step compile the myfile.c using this command.Make sure that your file has a main() function ,otherwise the produced myfile.exe will not be recognised by the debugger.
gcc -c myfile.c -o myfile.exe
  1. Add a launch configuration using gcc.
    • In the launch configuration manually add the path to the executable "program": "${workspaceFolder}/myfile.exe"
  • In the launch configuration
    manually add the path to the debugger "miDebuggerPath": "C:/MinGW/bin/gdb.exe"
Leguminous answered 21/5, 2022 at 9:39 Comment(0)
M
1

I had the same issue. For me what worked is deleting the folder .vscode and then re-add to 'view' > 'Add Folder to Workspace', the folder where my projects are.

See here.

Midriff answered 15/7, 2023 at 10:22 Comment(0)
B
1

If you are using c you have to run (or debug) the file that contains the main function.
If you are doing so, and you are using math.h library in your program, you have to open tasks.json by using shortcut:

ctrl+shift+p -> tasks:configure default build task

In the value of "args" key you will find an array of the arguments that will be passed to the compiler (or debugger) that is specified in the value of "command" key. Append the argument "-lm" to that array. Also if you are compiling a multifile project in the list of "args" change the "${file}" to "*.c"

Bioscope answered 15/7, 2023 at 16:17 Comment(0)
T
1

In my case i had 3 file which had main() function on all of them. this lead to cause failure build. Make sure you have only 1 file with main() function.

Tollefson answered 9/8, 2023 at 9:17 Comment(0)
C
1

Including the "${workspaceFolder}" in the "program" property fixed it for me. (I deleted it while monkeying around. Grr.)

"program": "${workspaceFolder}/main",   # i.e. not just "main"
Colier answered 13/12, 2023 at 21:40 Comment(0)
K
1

This might happen since default task.json "args": is empty and linking of multiple files is failure. Following solved the issue .exe does not exist:

"args": [
            "-g",
            "firstFile.cpp",
            "secondFile.cpp",
            "main.cpp",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],

After that, clicking Run and Debug did not failed by instructing launch.json. I could debug without terminal.

Kasiekask answered 29/2 at 22:39 Comment(0)
M
0

the problem for me was an error during the run time that the compiler didn't notice before. then the .exe file didn't built, therefore the .exe file does not exist so you have to check if your script is fine even if no error is found by the debugger.

Melonie answered 10/11, 2020 at 17:57 Comment(0)
C
0

In launch.json file where name : (Gdb) launch ,

step 1: enter the complete address of program for eg, c:/users/.....xyz.exe.

step 2: In Mi-debugger path complete address of bin in mingw folder which contains the Gdb debugger so the address would be c:/mingw/....gdb.exe repeat step 2 for the first configuration in launch.JSON

step 3 IN CWD , copy the same path but only till /bin

Calcic answered 14/7, 2021 at 13:20 Comment(0)
B
0

If you're using CMake, you could just add the CMake Tools extension and build/run debug from there. Worked for me.

Check out the link to the official CMake Tools extension or run ext install ms-vscode.cmake-tools from VSCode (Ctrl + Shift + P).

Barrington answered 25/6 at 23:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.