0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rustで linker cc not found が出たときの対処法

0
Posted at

問題

cargo runcargo test を実行した際に、以下のエラーが発生します。

$ cargo run
   Compiling sample v0.1.0 (/mnt/c/rust_project/sample)
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: could not compile `sample` (bin "sample") due to 1 previous error

このエラーは、Rust のビルドに必要な Cコンパイラ(cc がシステムに存在しない場合に発生します。

原因

cargo runcargo test 実行時、Rust コンパイラ(rustc)は内部的に Cコンパイラを呼び出すことがあります。しかし、Ubuntu 環境では初期状態で Cコンパイラがインストールされていないため、cc が見つからずエラーになります。

対応方法

build-essential パッケージをインストールして Cコンパイラや関連ツールを追加します。

sudo apt update
sudo apt install -y build-essential

インストール後、再度 cargo run または cargo test を実行してエラーが解消されたことを確認します。

動作環境

  • cargo 1.89.0
  • Ubuntu 24.04.3 LTS
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?