Skip to content

C++ code fails to build with clang 4.0 #3977

Closed

Description

@ulfjack

On a Ubuntu 17.04 machine, with clang-4.0 installed, I get this error from Bazel for some straightforward C++ code:

this rule is missing dependency declarations for the following files included by 'C-Source/something/other.c':
  '/usr/lib/llvm-4.0/lib/clang/4.0.0/include/stdbool.h'
  '/usr/lib/llvm-4.0/lib/clang/4.0.0/include/stdint.h'
  '/usr/lib/llvm-4.0/lib/clang/4.0.0/include/stddef.h'

Activity

  1. ulfjack commented on Oct 27, 2017

    @ulfjack
    ContributorAuthor

    Failing command line:

    $ CC=clang-4.0 bazel run -c opt --copt=-O2 :main
    

    It works with clang-3.9:

    $ CC=clang-3.9 bazel run -c opt --copt=-O2 :main
    
  2. ulfjack commented on Oct 27, 2017

    @ulfjack
    ContributorAuthor

    The -c and --copt parameters are not relevant. Same behavior without them.

  3. benjaminp commented on Oct 27, 2017

    @benjaminp
    Collaborator

    I think this is due to a Debian/Ubuntu patch that results in the clang installation system include directory being realpathed in the output of -v but not -MD.

  4. davido commented on Oct 27, 2017

    @davido
    Contributor

    FYI: Bazel cannot be built on GCC 7 too: #3903.

  5. added
    P2
    on Oct 31, 2017
  6. assigned and unassigned on Oct 31, 2017
  7. nicolasnoble commented on Feb 15, 2018

    @nicolasnoble

    Is there any bug entered in the Debian bug system about that if we believe this is on them?

  8. ulfjack commented on Feb 15, 2018

    @ulfjack
    ContributorAuthor

    Good point. I don't think we have.

  9. nicolasnoble commented on Feb 16, 2018

    @nicolasnoble

    Can I provide help in any way? This is currently a fairly big issue for us grpc folks. The link to the Debian patch provided by @benjaminp seems to be a 404 for me. If you an point me at the exact source of the problem in terms of actual patches links, I can start bugging Debian maintainers about it.

  10. ulfjack commented on Feb 16, 2018

    @ulfjack
    ContributorAuthor
  11. ulfjack commented on Feb 16, 2018

    @ulfjack
    ContributorAuthor

    Note that I haven't double-checked @benjaminp's statement, but he's usually right about these things.

  12. 33 remaining items

  13. ulfjack commented on May 17, 2018

    @ulfjack
    ContributorAuthor

    Unable to reproduce. What does your main.c file look like?

  14. tommadams commented on May 17, 2018

    @tommadams

    Discovered this issue because I'm unable to build grpc with clang & bazel. I can repro g-easy's build errors on gLinux. This is blocking development of tensorflow/minigo.


    Here's how I repro'd g-easy's example:

    $ which clang
    /usr/bin/clang
    
    $ clang --version
    clang version 4.0.1-10 (tags/RELEASE_401/final)
    Target: x86_64-pc-linux-gnu
    Thread model: posix
    InstalledDir: /usr/bin
    
    $ which bazel
    /usr/local/bin/bazel
    
    $ bazel version
    Build label: 0.13.0
    Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
    Build time: Mon Oct 18 21:33:40 +50297 (1525078013620)
    Build timestamp: 1525078013620
    Build timestamp as int: 1525078013620
    
    $ cat cc/bazel.c
    #include <stdlib.h>
    int main() { return 0; }
    
    $ cat cc/BUILD
    cc_binary(
        name = "bazel",
        srcs = ["bazel.c"],
    )
    
    # builds when not setting CC
    $ bazel build cc:bazel
    [succeeds]
    
    # builds with CC=gcc
    $ CC=gcc bazel build cc:bazel
    [succeeds]
    
    # does not build with CC=clang
    $ CC=clang bazel build cc:bazel
    INFO: Analysed target //cc:bazel (1 packages loaded).
    INFO: Found 1 target...
    ERROR: cc/BUILD:304:1: undeclared inclusion(s) in rule '//cc:bazel':
    this rule is missing dependency declarations for the following files included by 'cc/bazel.c':
      '/usr/lib/clang/4.0.1/include/stddef.h'
    Target //cc:bazel failed to build
    Use --verbose_failures to see the command lines of failed build steps.
    INFO: Elapsed time: 1.434s, Critical Path: 0.13s
    INFO: 0 processes.
    FAILED: Build did NOT complete successfully
    

    For completeness, here are the errors I get trying to build grpc's examples:greeter_client:

    $ bazel run examples:greeter_client
    WARNING: /usr/local/google/home/tmadams/grpc/BUILD:1973:1: in srcs attribute of cc_library rule //:grpc_nanopb: please do not import '//third_party/nanopb:pb_common.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /usr/local/google/home/tmadams/grpc/bazel/grpc_build_system.bzl:172:12
    WARNING: /usr/local/google/home/tmadams/grpc/BUILD:1973:1: in srcs attribute of cc_library rule //:grpc_nanopb: please do not import '//third_party/nanopb:pb_decode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /usr/local/google/home/tmadams/grpc/bazel/grpc_build_system.bzl:172:12
    WARNING: /usr/local/google/home/tmadams/grpc/BUILD:1973:1: in srcs attribute of cc_library rule //:grpc_nanopb: please do not import '//third_party/nanopb:pb_encode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /usr/local/google/home/tmadams/grpc/bazel/grpc_build_system.bzl:172:12
    INFO: Analysed target //examples:greeter_client (16 packages loaded).
    INFO: Found 1 target...
    ERROR: /usr/local/google/home/tmadams/.cache/bazel/_bazel_tmadams/4c83ceb29628e8749e4b91b77f6b4cd3/external/com_github_madler_zlib/BUILD.bazel:1:1: undeclared inclusion(s) in rule '@com_github_madler_zlib//:z':
    this rule is missing dependency declarations for the following files included by 'external/com_github_madler_zlib/adler32.c':
      '/usr/lib/clang/4.0.1/include/stddef.h'
      '/usr/lib/clang/4.0.1/include/__stddef_max_align_t.h'
      '/usr/lib/clang/4.0.1/include/limits.h'
      '/usr/lib/clang/4.0.1/include/stdarg.h'
    Target //examples:greeter_client failed to build
    Use --verbose_failures to see the command lines of failed build steps.
    INFO: Elapsed time: 12.545s, Critical Path: 0.30s
    INFO: 3 processes: 2 linux-sandbox, 1 local.
    FAILED: Build did NOT complete successfully
    ERROR: Build failed. Not running target
    
  15. g-easy commented on May 17, 2018

    @g-easy

    What does your main.c file look like?

    A single line:

    #include <stdint.h>
    
  16. ulfjack commented on May 18, 2018

    @ulfjack
    ContributorAuthor

    The fix unfortunately didn't make it into 0.13.0, but will be in 0.14.0 (you can see this in the GitHub UI when you click on the commit id c122e47 - it shows that it's in master, but it doesn't have any release tags). I tried @g-easy 's example with Bazel from HEAD, where it works for me.

  17. added
    P2
    and removed
    P1
    on May 18, 2018
  18. tommadams commented on May 18, 2018

    @tommadams

    Ah, ok. Thanks!

  19. soonho-tri commented on May 23, 2018

    @soonho-tri

    @ulfjack , is there a chance that c122e47 is included in the upcoming 0.13.1?

  20. ulfjack commented on May 23, 2018

    @ulfjack
    ContributorAuthor

    I believe we only cherrypick commits for regressions, not for bug fixes.

  21. ulfjack commented on May 23, 2018

    @ulfjack
    ContributorAuthor

    (That's a no.)

  22. nicolasnoble commented on May 23, 2018

    @nicolasnoble

    When is 0.14.0 scheduled then ?

  23. g-easy commented on May 24, 2018

    @g-easy
  24. lberki commented on May 24, 2018

    @lberki
    Contributor

    0.14 is slated for early next week, according to @lfpino , the current release manager.

  25. nicolasnoble commented on Jun 26, 2018

    @nicolasnoble

    I believe that since 0.14 has been released, this issue can be closed now, right ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2type: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions