Menu

Is --sysroot flag from compile_commands.json is taken into account by CppCheck

2024-05-28
2024-06-02
  • Ginson Mathew

    Ginson Mathew - 2024-05-28

    Hello,
    I am using CppCheck tool to run static code analysis on my embedded project. Here, I am using 32bit g++ compiler. I have generated compile_commands.json file which has the flag --sysroot.
    I am using Cppcheck 1.90 on Ubuntu 20.04LTS
    This is the command.
    cppcheck --project=build/compile_commands.json --check-config

    When i run this code, it throw file include error
    /home/user/embedded_proj/can/src/canapp.cpp:20:0: information: Include file: <cstring> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]

    /home/user/embedded_proj/can/src/canoutp.cpp:15:0: information: Include file: <thread> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    Just curious despite setting the sysroot variable cppcheck is complaining about missing include files.
    Is this something, that I am missing something?

    Thanks,

     

    Last edit: Ginson Mathew 2024-05-28
  • Daniel Marjamäki

    I recommend that the include paths for cstring and thread is not specified that can lead to false negatives. The standard functions are understood by internal knowledge in cppcheck. Please suppress or ignore missingIncludeSystem warnings for standard C/C++ headers. And for other 3rd party headers it's also usually better to use --library=.. when possible.

     
    • Daniel Marjamäki

      One reason there can be false negatives, I have seen cases when system headers define various functions using macros. For instance there is such code:

      #define strcpy(d, s) __builtin_strcpy ((d), (s))
      

      If you provide that to Cppcheck it will not be able to detect strcpy misuse.

      Another reason there can be false negatives is that sometimes there are complex ifdefs, templates, etc that is nontrivial to configure well. To start with, Cppcheck is not aware of all macros defined by your arbitrary compiler..

       

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.