bazelbuild/bazel

Documentation issue: Common C++ Build Use Cases

Open

#13,560 opened on 2021年6月8日

GitHub で見る
 (0 comments) (0 reactions) (0 assignees)Java (4,465 forks)batch import
P3help wantedteam-Documentationteam-Rules-CPPtype: documentation (cleanup)

Repository metrics

Stars
 (25,384 stars)
PR merge metrics
 (平均マージ 22d 20h) (30d で 77 merged PRs)

説明

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

コントリビューターガイド