Documentation issue: Common C++ Build Use Cases
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
Documentation URL: https://docs.bazel.build/versions/master/cpp-use-cases.html
Hi!
I've been delving into Bazel recently and ran into some issues while doing the tutorial on this page. Here is the error I ran into initially:
> Use --sandbox_debug to see verbose messages from the sandbox
> test/hello-test.cc:1:10: fatal error: 'gtest/gtest.h' file not found
> #include "gtest/gtest.h"
> ^~~~~~~~~~~~~~~
> 1 error generated.
> Target //test:hello-test failed to build
> INFO: Elapsed time: 0.379s, Critical Path: 0.26s
> INFO: 3 processes: 3 internal.
> FAILED: Build did NOT complete successfully
> //test:hello-test FAILED TO BUILD
> FAILED: Build did NOT complete successfully
I figured out the problem to be the `WORKSPACE` and `gtest.BUILD` files in the current version of the tutorial. With the `googletest` release `1.10.0` their contents should be:
> $ cat WORKSPACE
> load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
>
> http_archive(
> name = "gtest",
> url = "https://github.com/google/googletest/archive/release-1.10.0.zip",
> sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
> build_file = "@//:gtest.BUILD",
> strip_prefix = "googletest-release-1.10.0/googletest",
> )
>
> http_archive(
> name = "rules_cc",
> urls = ["https://github.com/bazelbuild/rules_cc/archive/40548a2974f1aea06215272d9c2b47a14a24e556.zip"],
> strip_prefix = "rules_cc-40548a2974f1aea06215272d9c2b47a14a24e556",
> )
> $ cat gtest.BUILD
> cc_library(
> name = "gtest_main",
> srcs = glob(
> include = [
> "src/*.cc",
> ],
> exclude = [
> "src/gtest-all.cc",
> ],
> ),
> hdrs = glob([
> "src/*.h",
> "include/gtest/**/*.h",
> ]),
> includes = [
> ".",
> "include",
> ],
> linkopts = ["-pthread"],
> visibility = ["//visibility:public"],
> )
Also, the contents of `test/BUILD` file should be:
> $ cat test/BUILD
> cc_test(
> name = "hello-test",
> srcs = ["hello-test.cc"],
> deps = [
> "@gtest//:gtest_main",
> "//main:hello-greet",
> ],
> )
The aforementioned issue was encountered in this environment:
> [16:34:04 1.01 stage4]$ bazel --version
> bazel 4.0.0-homebrew
> [16:37:07 1.01 stage4]$ gcc --version
> Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
> Apple clang version 12.0.0 (clang-1200.0.32.28)
> Target: x86_64-apple-darwin19.6.0
> Thread model: posix
> InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Regards,
Valeriu
Contributor guide
Research direction
Start with the Common C++ Build Use Cases page at docs.bazel.build/versions/master/cpp-use-cases.html and compare its tutorial references with the reported WORKSPACE, gtest.BUILD, and test/BUILD contents. Verify the tutorial with Bazel 4.0.0 and confirm that the documented example builds the hello-test target without the missing gtest/gtest.h error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100