bazel coverage link error for C targets on macOS

Created on 1 May 2018  路  5Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

When building any cc_test target or cc_binary target with coverage instrumentation on macOS, bazel coverage fails with an error like this:

>>>>>>>>> # //:hello_lib [action 'Linking libhello_lib.so']
(cd /private/var/tmp/_bazel_jayconrod/dc23ec2471431a08def1a3ea88cf8238/execroot/__main__ && \
  exec env - \
    APPLE_SDK_PLATFORM='' \
    APPLE_SDK_VERSION_OVERRIDE='' \
    XCODE_VERSION_OVERRIDE=8.3.3 \
  external/local_config_cc/cc_wrapper.sh -fobjc-link-runtime -Wl,-S -shared -o bazel-out/darwin-fastbuild/bin/libhello_lib.so bazel-out/darwin-fastbuild/bin/_objs/hello_lib/hello.o -lgcov -headerpad_max_install_names -lc++ -no-canonical-prefixes -undefined dynamic_lookup)
ERROR: /Users/jayconrod/go/src/example.com/repo/BUILD.bazel:6:1: Linking of rule '//:hello_lib' failed (Exit 1).
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

// hello.c
int main() {return 0;}
# BUILD.bazel
cc_test(
    name = "hello",
    deps = [":hello_lib"],
)

cc_library(
    name = "hello_lib",
    srcs = ["hello.c"],
)
$ bazel coverage //:hello

What operating system are you running Bazel on?

macOS High Sierra 10.13.4

What's the output of bazel info release?

release 0.13.0

Any other information, logs, or outputs that you want to share?

It looks like -lgcov is being passed on the command line to the linker. macOS doesn't seem to have this library. Maybe passing --coverage would be better? That works for me in small examples on both macOS and Linux, both gcc and clang.

coverage apple

Most helpful comment

-lgcov was replaced with --coverage in d6f706d334046601df9d0a58b993b705e9e371a0, so this should be fixed with the next release. There are a few more places that use -lgcov which should be changed as well.

All 5 comments

-lgcov was replaced with --coverage in d6f706d334046601df9d0a58b993b705e9e371a0, so this should be fixed with the next release. There are a few more places that use -lgcov which should be changed as well.

Looks like it is still broken in 0.14.1:

$ bazel info release
release 0.14.1-homebrew
$ bazel coverage -s ...

ERROR: /private/var/tmp/_bazel_zaytsev/031680ef6cb503622683e0f635fcc447/external/com_google_grpc/BUILD:1089:1: Linking of rule '@com_google_grpc//:grpc_server_load_reporting' failed (Exit 1)
ld: library not found for -lgcov
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Target //cli/cmds:go_default_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.737s, Critical Path: 0.39s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Can someone verify if this is still happening with the latest Bazel release?

This is still happening in 0.15.2, but I can't reproduce anymore in 0.16.0-rc3. Thanks for fixing it!

Thanks for checking!

Was this page helpful?
0 / 5 - 0 ratings