rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.89k stars 1.54k forks source link

linker `cc` not found when building proc macros #14418

Open HmFlashy opened 1 year ago

HmFlashy commented 1 year ago

When building my project, I get the following errors: I doesn't do any harm for my developer experience, since it is still indexing my proejct etc... but I get a warning and this message "Failed to run build scripts of some packages" in the little tab in the bottom of VS code

I don't know why it is throwing these errors since I have all gcc, cc, cmake etc... installed correctly and it was working before

[ERROR rust_analyzer::main_loop] FetchBuildDataError:
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `proc-macro-error-attr` due to 2 previous errors
error: could not compile `num-integer` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `num-traits` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `generic-array` due to 2 previous errors
error: could not compile `ahash` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `getrandom` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `num-bigint` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

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

error: aborting due to previous error

error: aborting due to previous error

error: could not compile `serde` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `memchr` due to 2 previous errors
error: could not compile `quote` due to 2 previous errors
error: could not compile `syn` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `serde_derive` due to 2 previous errors
error: could not compile `libc` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `io-lifetimes` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `proc-macro2` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `typenum` due to 2 previous errors

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

error: aborting due to previous error

error: could not compile `indexmap` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `proc-macro-error-attr` due to 2 previous errors
error: could not compile `proc-macro-error` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `log` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `memchr` due to 2 previous errors
error: could not compile `serde_json` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `anyhow` due to 2 previous errors
error: could not compile `semver` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `io-lifetimes` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `rustix` due to 2 previous errors

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

error: aborting due to previous error

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

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `proc-macro-error-attr` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: could not compile `num-integer` due to 2 previous errors
error: aborting due to previous error

error: could not compile `num-traits` due to 2 previous errors
error: could not compile `generic-array` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `proc-macro-error` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `getrandom` due to 2 previous errors
error: could not compile `serde_derive` due to 2 previous errors
error: could not compile `quote` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `libc` due to 2 previous errors
error: could not compile `num-bigint` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `memchr` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

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

error: aborting due to previous error

error: aborting due to previous error

error: could not compile `serde` due to 2 previous errors
error: could not compile `io-lifetimes` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

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

error: aborting due to previous error

error: could not compile `syn` due to 2 previous errors
error: could not compile `proc-macro2` due to 2 previous errors
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error

error: could not compile `typenum` due to 2 previous errors

rust-analyzer version: 0.4.1450-standalone

rustc version: rustc 1.69.0-nightly (c8e6a9e8b 2023-01-23)

image

bjorn3 commented 1 year ago

Does cargo check --workspace --all-targets work? This is what rust-analyzer runs. Also how are you running VSCode? Did you install it as pacman package, as flatpak application or in some other way? Does where cc (that is cc without a g) work?

HmFlashy commented 1 year ago

Indeed cargo check --workspace --all-targets works I downloaded vscode with snap. And where cc works with the result /usr/bin/cc

bjorn3 commented 1 year ago

What does snap info --verbose code and snap connections code show? I suspect that the sandbox settings are set too strict, preventing access to cc from within the vscode snap.

HmFlashy commented 1 year ago
name:    code
summary: Code editing. Redefined.
health:
  status:  unknown
  message: health has not been set
publisher: Visual Studio Code (vscode✓)
store-url: https://snapcraft.io/code
contact:   https://twitter.com/code
links:
  contact:
    - https://twitter.com/code
  website:
    - https://code.visualstudio.com/
license: unset
description: |
  Visual Studio Code is a new choice of tool that combines the
  simplicity of a code editor with what developers need for the core
  edit-build-debug cycle.
commands:
  - code
  - code.url-handler
notes:               
  private:           false
  confinement:       classic
  devmode:           false
  jailmode:          false
  trymode:           false
  enabled:           true
  broken:            false
  ignore-validation: false
snap-id:      Ht0aUHi7ofh9Fbwh6m7jUN2pAy6kzBiu
tracking:     latest/stable
refresh-date: 6 days ago, at 09:41 CET
channels:
  latest/stable:    ee2b180d 2023-03-15 (122) 250MB classic
  latest/candidate: ↑                               
  latest/beta:      ↑                               
  latest/edge:      ↑                               
installed:          ee2b180d            (122) 250MB classic
HmFlashy commented 1 year ago

I get no result from snap connections code

HmFlashy commented 1 year ago

Update: I removed and installed vscode from https://aur.archlinux.org/packages/visual-studio-code-bin So there is no sandbox, and there is still the same error

bjorn3 commented 1 year ago

Did you set the PATH env var using rust-analyzer.server.extraEnv? If so maybe this is the same issue as https://github.com/rust-lang/rust-analyzer/issues/14420? That is $PATH doesn't get expanded, requiring you to manually write the full content you want PATH to have.

HmFlashy commented 1 year ago

Indeed

"rust-analyzer.server.extraEnv": {
        "PATH": "${env:HOME}/multiversx-sdk:${env:HOME}/multiversx-sdk/vendor-rust/bin:${env:HOME}/multiversx-sdk/vmtools:${env:PATH}",
        "RUSTUP_HOME": "${env:HOME}/multiversx-sdk/vendor-rust",
        "CARGO_HOME": "${env:HOME}/multiversx-sdk/vendor-rust"
    },
HmFlashy commented 1 year ago

It works well because I can develop and build what I am developing, just I have this error

HmFlashy commented 1 year ago

I removed the PATH from this settings and it worked, you were right

kennystrawnmusic commented 1 year ago

Did you set the PATH env var using rust-analyzer.server.extraEnv? If so maybe this is the same issue as #14420? That is $PATH doesn't get expanded, requiring you to manually write the full content you want PATH to have.

Well I did paste the entire contents of the PATH variable there back when #14420 was open and nothing changed — still getting that barrage of errors from rust-analyzer despite being able to build everything successfully otherwise. I wonder therefore if the non-default $RUSTUP_HOME/$CARGO_HOME has something to do with it.