在WSL中安装 bazel 后,无法执行 bazel run
The installation method is as follows: Step 1: Add the Bazel release URI as a package source sudo apt install apt-transport-https curl gnupg -y curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor >bazel-archive-keyring.gpg sudo mv bazel-archive-keyring.gpg /usr/share/keyrings echo "deb [arch=amd64 signed-by=/usr/share/keyrings/bazel-archive-keyring.gpg] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list Step 2: Install and update Bazel sudo apt update sudo apt install bazel After installation, run `bazel run //practical_exercises/10_day_practice/day1:union` and get the following error: WARNING: Target pattern parsing failed. ERROR: Skipping '//practical_exercises/10_day_practice/day1:union': error loading package 'practical_exercises/10_day_practice/day1': Unable to find package for @@[unknown repo 'rules_cc' requested from @@]//cc:defs.bzl: The repository '@@[unknown repo 'rules_cc' requested from @@]' could not be resolved: No repository visible as '@rules_cc' from main repository. ERROR: error loading package 'practical_exercises/10_day_practice/day1': Unable to find package for @@[unknown repo 'rules_cc' requested from @@]//cc:defs.bzl: The repository '@@[unknown repo 'rules_cc' requested from @@]' could not be resolved: No repository visible as '@rules_cc' from main repository. INFO: Elapsed time: 0.056s INFO: 0 processes. ERROR: Build did NOT complete successfully ERROR: Build failed. Not running target My solution is as follows: Write in `CPlusPlusThings/MODULE.bazel` (if there is no such file, you can run `bazel run //practical_exercises/10_day_practice/day1:union`) bazel_dep(name = "rules_cc", version = "0.0.9") Run again, the result is as follows: WARNING: For repository 'rules_cc', the root module requires module version [email protected], but got [email protected] in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off INFO: Analyzed target //practical_exercises/10_day_practice/day1:union (87 packages loaded, 468 targets configured). INFO: Found 1 target... Target //practical_exercises/10_day_practice/day1:union up-to-date: bazel-bin/practical_exercises/10_day_practice/day1/union INFO: Elapsed time: 1.010s, Critical Path: 0.01s INFO: 1 process: 6 action cache hit, 1 internal. INFO: Build completed successfully, 1 total action INFO: Running command line: bazel-bin/practical_exercises/10_day_practice/day1/union 0 5 6 0
内容来源: Light-City/CPlusPlusThings