VSCode error: linker `cc` not found | = note: No such file or directory (os error 2)

I found these 2 threads here and here, but my problem is specific to vscode. I can compile and run test using cargo build and cargo test in terminal without a problem, and the program cc can be found at /usr/bin/cc.

$ which cc
/usr/bin/cc

My problem is when each time I edit and change the source code e.g. test case, I need to explicitly execute the command cargo test in terminal. Then, pressing Run test button inside vscode IDE would work. Otherwise, vscode will throw error: linker cc not found.

This problem seems to me that vscode does not sourcde .profile, where there exist the steps to activate rust env setting.

# rust env
. "$HOME/.cargo/env"

export LIBCLANG_PATH=/usr/lib/llvm-21/lib/libclang.so

However, I am not sure where to configure to fix this error in vscode. I attempted to add related setting to ~/.config/Code/User/settings.json, but it does not work.

"terminal.integrated.env.linux": {
    "PATH": "${env:PATH}:/usr/bin/",
    "LIBCLANG_PATH": "/usr/lib/llvm-21/lib/libclang.so"
}

How should I fix this error? Thanks.

what distribution are you using? is your vscode installed in a sandboxed environment, such as flatpak? what's the output if you run the env command from the integrated terminal?

Sorry replying lat. I uses Debian Trixie. The vscode is installed by apt-get by configuring vscode repository.

$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"
VERSION_ID="13"
VERSION="13 (trixie)"
VERSION_CODENAME=trixie
DEBIAN_VERSION_FULL=13.0

The env output is Being, between himself and hung about him, loudly and offensively, as.
Please let me know if more information is needed. Thanks.

usually, the .profile is sourced when you login, thus the environment variables are inherited by the entire user session. I'm not sure why your vscode installation didn't inherit them.

to quickly verify this is indeed the cause, try launch vscode from your shell (as opposed to launch from the desktop app launcher), make sure cargo can build your program successfully within the shell first:

$ cargo test
$ code .

the easiest workaround I can think of to override the environment variables of an app is to modify the entry in the desktop launcher. on KDE, I can right click an entry and select "Edit Application", I don't use Gnome, but I think there's something similar. you can also edit the .desktop file manually. for example:

I also checked online, and like you mentioned vscode should inherit env after login, but my case is weird because even setting.json already is marked the base as login shell.

"terminal.integrated.profiles.linux": {
    "bash": {
        "path": "/usr/bin/bash",
        "icon": "terminal-bash",
        "args": [
            "-l"
        ]
    },
    ...
}

But I found a workaround by editing $HOME/Code/User/setting.json extraEnv key as below, where /usr/bin is the parent dir of linker cc e.g. which cc.

"rust-analyzer.server.extraEnv": {
    "PATH": "$PATH:/usr/bin/"
},

Thanks for helping out and the advice!