Menu

Compile database and checkers

2024-06-05
2024-06-17
  • Yannick Dannel

    Yannick Dannel - 2024-06-05

    Dear,

    I try to use the CPPChek GUI to do a static analysis of my code code.
    I use CMake to generate compile database file (compile_commands.json).

    And when I create a project importing this file, no error are show on my code (even if I do a specific mistake) except for the missing include system.
    And when I do a directories analyze, I see all the errors.
    (Same when I used the command line)

    When I check the checkers, I have nothing enable when I used the project (see the attachment).

    How can I enable checkers with a project ?

     
    • Dzid

      Dzid - 2024-06-06

      I have that behaviour if I don't set -D__GNUC__=9, but I don't understand why.

       
      • Daniel Marjamäki

        Do you have critical errors? The checkers report should show if you have critical errors at the top.

        --checkers-report=report.txt

        In the GUI you can see the checkers report in the statistics window.

         
        • Dzid

          Dzid - 2024-06-06

          No, I don't get critical errors.
          The only checkers that stay on are:

          Yes  CheckBufferOverrun::analyseWholeProgram
          Yes  CheckClass::analyseWholeProgram
          Yes  CheckNullPointer::analyseWholeProgram
          Yes  CheckUnusedFunctions::check
          Yes  Misra C 2012: 1.1
          Yes  Misra C 2012: 1.3
          Yes  Misra C 2012: 9.1
          Yes  Misra C 2012: 18.6
          Yes  Misra C 2012: 20.6
          Yes  Misra C 2012: 22.1
          

          nofile:0:0: information: Active checkers: 10/1002

           

          Last edit: Dzid 2024-06-06
  • Daniel Marjamäki

    It seems that you have critical errors when you use the compile database.

     
  • Yannick Dannel

    Yannick Dannel - 2024-06-11

    Sorry for this late reply.

    Yes, I have an error (preprocessorErrorDirective) and yes, I use GCC to compile.
    This error is in a header file in library folder I use. It automatically define some macro depending the compiler.
    With the GUI, I'm not able to modify the project setting (path, include, ...) when importing a compile database.

     
    • Daniel Marjamäki

      that preprocessorErrorDirective must be fixed. Otherwise all the checkers will be skipped.

      With the GUI, I'm not able to modify the project setting (path, include, ...) when importing a compile database.

      If you use latest Cppcheck then you can configure extra defines. I would assume that you can fix the preprocessorErrorDirective with an extra define. Can you show the ifdef(s) before the #error ?

       
      • Yannick Dannel

        Yannick Dannel - 2024-06-13

        I use the latest version (2v.14.0)

        yeah, the error directive is because there is no compiler defined (GCC in my case)
        and all is disable when I try to edit the project

         
        • Daniel Marjamäki

          I thought it was enabled in 2.14.1 but it seems not. I will probably tag 2.14.2 in near future I will put the change in that.

          A workaround that I think should work in 2.14.0 is;
          1. clear the compile_commands.json so the paths and defines are enabled
          2. write __GNUC__ in the defines textbox
          3. readd the compile_commands.json

           

          Last edit: Daniel Marjamäki 2024-06-13
          • Yannick Dannel

            Yannick Dannel - 2024-06-13

            OK, it seems to work by setting the extra define before the database file

            I don't see the error during the analyze

            But cppcheck crashs just before the end of the analyze (at 99%)

             
            • Daniel Marjamäki

              does it happen in command line also? use --project=yourproject.cppcheck to import the GUI project file.
              it would be interesting if you could pinpoint the crash and imho the best way is if you compile and run cppcheck in debug mode. The command-line tool is pretty straight forward to compile imho. The GUI is not difficult to build but you need a Qt SDK not just a C++ compiler.

               

              Last edit: Daniel Marjamäki 2024-06-13
              • Yannick Dannel

                Yannick Dannel - 2024-06-17

                It craches on CLI too.

                I will try to do it in debug mode.

                 

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.