Launch: program " does not exists in Visual Studio Code

I installed Rust by the steps on rust-lang.org: right top: button "Get started". After pressing this button, on this webpage:

Installing rustup, restart

Other tools: pressing the button "VS Code". Installing Visual Studio Code, and the extensions: rust-analyzer, Microsoft C++: while installing this, a compiler must be selected: I selected "cl", because of Visual Studio 2019 is already installed.

Command line: cargo new hello_world

I opened this with VS Code, and in the source code, appered 2 buttons: Run, Debug. These work, but the program runs inside the build window, not in a separated console window. The commands in the Run menu does not work: Run (F5), Run without debugging (CTRL+F5). At these, I must choose a debugger: I choosed C++ (Windows), but the other does not work so. I get the error message:

launch: program " does not exists

There is a button "Open 'launch.json'": this file is:

{
    // 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": [
        

    ]
}

There is an "Add configuration" button, but Rust is not on the list, and there are a lot of C++ configuration, I tried 1, but this does not work. I installed the extension vscode-runner so, but this did not help me.

I am a practised programmer in C++ with Visual Studio 2019 Community, but an absolute beginner in VS code. But I installed the extension for Haskell so. (And before it, Haskell by command prompt). Another extensions does not installed.

these are "code lenses" added by the rust-analyzer vscode extension, and it's the most convenient way to run or debug rust program in vscode, because there will potentially be more than one runnables in a single rust crate, like bin targets, examples, unit tests, integration tests, doc tests, etc. the launch configurations are generated on the fly so it won't get outdated as the code changes.

if you prefer using static launch configurations, it is also supported. here's the simplest way without having to manually edit a launch.json file:

you'll need to install the CodeLLDB extension in addition to rust-analyzer. wait for CodeLLDB to automatically install a custom built lldb for your operating system. once installed, open a rust source file in the editor, just hit F5 choose lldb, it will prompt you something like "found Cargo.toml, would you like to generate debug target automatic", just accept, and you'll have a launch.json file.

this is controlled by a codelldb configuration. press Ctrl-, (note: Ctrl key combined with the comma key) to open the "settings" page, and search "lauch terminal type", "default" will use the integrated terminal, select "external" to open a separate console window.

C++ configurations doens't quite work for rust, at least not out of the box. please install CodeLLDB. with CodeLLDB installed, if you hit "Add configuration" button, you should see "CodeLLDB: debug cargo target" and "CodeLLDB: debug cargo test" for binary targets and tests, respectively.

2 Likes

Thank you your answer, but:
I installed CodeLLDB, but this has no effect. I added the 2 configuration. Ctrl+ enlarges the letters. At the USA keyboard layout, + is 2 after 9: √ú at me. Ctrl+√ú inserts comment (//), so I have no settings page. F5: I get an error messaege:

unning cargo test --no-run --lib --message-format=json...
error: no library targets found in package hello_world
Error: Cargo invocation failed.
at t.Cargo.getCargoArtifacts (c:\Users\Programoz√°s.vscode\extensions\vadimcn.vscode-lldb-1.9.2\extension.js:1:15379)
at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Object.open (c:\Users\Programoz√°s.vscode\extensions\vadimcn.vscode-lldb-1.9.2\extension.js:1:13689)
Caused by: Error: exit code: 101.
at ChildProcess. (c:\Users\Programoz√°s.vscode\extensions\vadimcn.vscode-lldb-1.9.2\extension.js:1:17046)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1121:16)
at ChildProcess._handle.onexit (node:internal/child_process:304:5)

  • The terminal process failed to launch (exit code: 1).
  • Terminal will be reused by tasks, press any key to close it.

I opened the project created by command "cargo new" with VS Code (menu File / Open Folder...), and I can not close it (there is no "close" in the menu), so if I opened an individual .rs file, VS Code regards this as part of the project, and wants to build the project. So, all the problems remain.

After pressing F5, the choosing is disappeared.

Update: using the button "manage" on left bottom, I set the terminal to "external". This has no effect.

please improve your formatting, your post is very hard to read.

this error:

indicates the launch task is trying to build a lib crate but your project is a bin crate. hmmm, seems a bug in CodeLLDB.

but the auto generated launch.json should always work. try remove the launch.json file and hit F5, you should see an error message saying can't find a launch configuration, followed by a prompt like this:

image

press yes and it should automatically generate a launch.json file based on your Cargo.toml, then you can debug as normal.

if all that fails, you can try this: press Ctrl-P and type "lldb cargo", there's should be a command "LLDB: generate launch configurations from Cargo.toml", press Enter, it will open a new file with the correct configuration, just copy and paste that into your launch.json file and save it.

if you never used the vscode editor, I suggest you first get write some C++ code (which, I assume shoube be more comfortable to you) so you can get familiar with editor itself.

1 Like

Thank you. So, do not Ctrl+ but Ctrl+, (Ctrl and comma), but this has effect only debug mode: if I click ro "Run", has no effect.

Yo do not mentioned internet connection is required after deleting launch.json. After connecting to internet, your method works. At now, there is only Debug, no Release: I can press Ctrl+F5, but the configuration remained "Debug executable 'hello_world'. So, it seems compiles debug version of the .exe, but starts only the .exe, without debugger. So, it seems I cannot build a release version of the .exe file.
With F5, Ctrl+F5, the program runs in a separated console window, so, this is solved, thank you.

vscode is not an IDE like Visual Studio, the launch configuration is mainly for debugging uses. if you want to build a release profile, you should run cargo directly from the command line, either within the integrated terminal of vscode or a standalone cmd.exe or powershell, just cd into your project directory and run cargo build --release

1 Like

It is possible to configure launch to run in release, in case you want to debug a release build specifically.

2 Likes