Skip to content

'stddef.h' file not found #121

Closed
Closed

Description

@GewoonJaap

I am trying to run the clang-tidy action however I am getting the following error:

INFO:CPP Linter:Running "clang-tidy-12 --export-fixes=clang_tidy_output.yml -checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-*,cppcoreguidelines-* --extra-arg= src/main.cpp"
  DEBUG:CPP Linter:Output from clang-tidy:
  /usr/include/wchar.h:35:10: error: 'stddef.h' file not found [clang-diagnostic-error]
  #include <stddef.h>

I am not getting this error on my local PC or with any of my GH Actions build scripts, only the clang-tidy action throws this error. How to fix/ignore this?

Activity

  1. 2bndy5 commented on Nov 5, 2022

    @2bndy5
    Collaborator

    We are still trying to understand why this is happening, but we are aware of this.

    The only known workaround that we can recommend is to use the cpp-linter pkg manually via

    pip install cpp-linter
    

    and ensure the version of clang-tidy and/or clang-format is installed before using the cpp-linter CLI.

  2. shenxianpeng commented on Nov 5, 2022

    @shenxianpeng
    Member

    Are you using the latest version of cpp-linter-action? Like v2 or v2.2.0

    Could you please share your cpp-linter configuration here?

  3. GewoonJaap commented on Nov 5, 2022

    @GewoonJaap
    Author

    Currently using @main, but V2 had the same issue. It's strange that one of my repos works fine with the linter while the other one gives this error.

    Repo with error has a submodule to the repo thag works and just a hello world file, so nothing exciting there

  4. GewoonJaap commented on Nov 5, 2022

    @GewoonJaap
    Author

    We are still trying to understand why this is happening, but we are aware of this.

    The only known workaround that we can recommend is to use the cpp-linter pkg manually via

    pip install cpp-linter
    

    and ensure the version of clang-tidy and/or clang-format is installed before using the cpp-linter CLI.

    I will try that in a bit. Any chance you have a GitHub action file I can CTRL + C ;)

  5. 2bndy5 commented on Nov 5, 2022

    @2bndy5
    Collaborator

    I will try that in a bit. Any chance you have a GitHub action file I can CTRL + C ;)

    Its a bit old (untested for a few months), but it should still work with any runner on github: Try this code snippet in the README on master. You'll still have to tweak it for your project (obviously), but its a good start.

  6. 2bndy5 commented on Nov 5, 2022

    @2bndy5
    Collaborator

    Keep in mind that the Ubuntu runner already comes with v12 of clang tools, so you may only need the stuff specific to cpp-linter steps.

  7. GewoonJaap commented on Nov 5, 2022

    @GewoonJaap
    Author

    Thanks! Will try that one out. Just thinking, could it have something to do with git submodules? Because the referenced .h file is only used in one of my submodules. I tried to ignore the entire folder, but it didn't help sadly..

  8. 2bndy5 commented on Nov 5, 2022

    @2bndy5
    Collaborator

    Like I said we've looked into it and got stumped. This problem has been reported from repos that don't use submodules. Our test repo also uses a submodule, but any submodule's path is automatically ignored by cpp-linter. It wouldn't make sense to tell cpp-linter to analyze someone else's repo that your using in your repo, although it could be done with the --ignore option.

    The problem that I see is that clang-tidy doesn't know where to find stddef.h when analyzing any header that includes it in the C std libs. The fact that this doesn't happen locally makes this problem hard to diagnose.

  9. 2bndy5 commented on Nov 5, 2022

    @2bndy5
    Collaborator

    Its not specific to Ubuntu runners either. Windows runners show the problem too. It does seem to happen with clang-tidy-12 more than others, but it still does happen with other clang-tidy versions. My best guess is that the runner's C std lib is not the version that clang-tidy was built for (??) 🤷🏼

  10. 2bndy5 commented on Nov 5, 2022

    @2bndy5
    Collaborator

    We could be a bit more helpful if the repo was public and you provided a link.

  11. GewoonJaap commented on Nov 5, 2022

    @GewoonJaap
    Author

    Sadly the repo is private and I am unable to make it public

  12. 2bndy5 commented on Nov 5, 2022

    @2bndy5
    Collaborator

    That's unfortunate here but understandable in the bigger picture.

  13. shenxianpeng commented on Nov 12, 2022

    @shenxianpeng
    Member

    I think this issue should have been fixed in the latest release, #103 (comment)
    If you could not provide your cpp-linter YAML config file, it's hard to tell what exactly the reason is.

  14. shenxianpeng commented on Nov 21, 2022

    @shenxianpeng
    Member

    Please feel free to reopen if this problem still exists or you could provide your cpp-linter YAML config file.

  15. ClemensLinnhoff commented on Feb 3, 2023

    @ClemensLinnhoff

    I am having the same issue of 'stddef.h' file not found in various files. You can check out this, where you will also find the yaml config file.

  16. 2bndy5 commented on Feb 3, 2023

    @2bndy5
    Collaborator

    This still eludes me... I think it has something to do with certain versions of clang-tidy and the installed C std libs. A while back, I found a stackoverflow suggestion that recommended using the C std lib from LLVM project (instead of the OS-specific PPA), but I don't think that solution is the right approach here.

  17. reopened this on Feb 3, 2023
  18. ClemensLinnhoff commented on Feb 6, 2023

    @ClemensLinnhoff

    @GewoonJaap did you find a fix for your private repository? Because with this error the cpp-linter is not really usable as it flags basically every file.

    @2bndy5 Additionally we have other problems with the linter. Multiple header files are not found, although the compiler does not have a problem with it and we do a complete build within the pipeline, so that the compile_commands.json can be used. Probably in correlation with this error, some functions are marked as "can be made static" which are already declared static in the corresponding header file. So there seems to be a general problem with finding the correct headers. Do you have any idea how to fix this?

  19. shenxianpeng commented on Feb 6, 2023

    @shenxianpeng
    Member

    From the output of the above problematic job, it looks like cpp-linter-action doesn't use native binaries.

    Found a installed version of clang-format: 12.0.1 at /usr/lib/llvm-12/bin/clang-format
    downloading clang-format (version 12)
    Installing clang-format-12 to /home/runner/.local/bin/
    symbolic link created /home/runner/.local/bin/clang-format
    Found a installed version of clang-tidy: 12.0.1 at /usr/lib/llvm-12/bin/clang-tidy
    downloading clang-tidy (version 12)
    Installing clang-tidy-12 to /home/runner/.local/bin/
    symbolic link created /home/runner/.local/bin/clang-tidy

    Try adding version and setting it to '14' might fix 'stddef.h' file not found

    - name: Lint CPP
      uses: cpp-linter/cpp-linter-action@v2
      id: linter
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        style: file
        tidy-checks: ''
        version: '14'
        files-changed-only: false
        thread-comments: true
        database: 'build/'
        ignore: 'build | protobuf-3.15.8 | .github'
  20. 2bndy5 commented on Feb 6, 2023

    @2bndy5
    Collaborator

    TBH, our python script doesn't do anything special. It simply finds source files and feeds them to clang-format and/or clang-tidy. The problems you're reporting here sound more like problems with clang-tidy. Since I didn't author anything in the clang project, I can't confidently make any sound suggestions. It would be better to be able to reproduce this locally, but we've been unsuccessful on that front.

    That said, have you tried using a different version of clang-tidy? ubuntu-latest (currently Ubuntu-22.04) ships with v12, v13, and v14, so I'd recommend trying those because, as I said before, I think this problem is largely related to using certain versions of clang-tidy with certain version of the C/C++ std libs. It should be noted that each major version of the clang project isn't fully backward compatible, so the specified version is important.

    Probably in correlation with this error, some functions are marked as "can be made static" which are already declared static in the corresponding header file.

    You're PR covers so many files, its not good to assume that the problems are related. In fact, this is the first I'm hearing about this error. My first impression makes me think there's a discrepancy between the implementation file and the header, but IDK.

    We currently don't have a plan to support filtering the output captured from clang-tidy, and we cannot support using a special set of rules for certain files (which should be possible with multiple .clang-tidy config files).


    Try adding version and setting it to '14' might fix 'stddef.h' file not found

    Good catch @shenxianpeng ! If using the native v12 binary is desired, then the version option should specify 12.0.1 which might include the a fix (though I doubt it). The ubuntu-20.04 runners ship with v12.0.0.

  21. ClemensLinnhoff commented on Feb 6, 2023

    @ClemensLinnhoff

    Specifying to use clang version 14 did fix the stddef.h error! Thank you for the suggestion!

    The other errors remain, but I will try to replicate them offline.

  22. 2bndy5 commented on Feb 6, 2023

    @2bndy5
    Collaborator

    I'm closing this. Its worth opening a new issue to track the "could be made static" problem.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions