c++jsonvisual-studio-codecompiler-errors

Vscode Run with debugger error "Launch program *file/path* does not exist


json file

I'm trying to figure out what's wrong with my complier or launch.json file. I get an error whenever i try to run a simple program in vs code. The error says, "Launch program file_path does not exist. I tried downloading different compliers and adding different paths to my system environment variables. I'm losing faith at this point.


Solution

  • I think I know which one is your issue, let me show you a quick example:

    I have a folder called Test, having only Test.cpp file:

    My Folder

    Then the Test.cpp is only having this simple code:

    #include <iostream>
    
    using namespace std;
    
    int main(){
        cout<<"Hello World!"<<endl;
        return 0;
    }
    

    To compile the code and execute it I am using this documentation , checking your launch.json file I saw that you are using the same, but your problem is in your launch.json specifically in the variable called program: enter image description here

    VS Code is trying to execute your program with just the workspace folder and that's causing an error, you should use this value on the variable to run and debug the program without issues:

    "program": "${fileDirname}\\${fileBasenameNoExtension}.exe"
    

    ${fileDirname} - the current opened file's dirname

    ${fileBasenameNoExtension} - the current opened file's basename with no file extension

    In that way VS Code can run and debug the executable that was generated after compiling the code, in my example I opened the file called test.cpp to do the run because the executable was generated from that one. Here is the order of the folders at the end:

    Folders at the end

    I recommend you to read this article with the variables for the JSON files on VS Code and this one.