Hi guys, I've looked through the entire forum for a hint, but didn't find anything similar to my question.
I'm trying to configure Cppcheck to analyze a basic project that contains both C and C++ sources using the "--file-list" option. The problem here is that I need to pass a different set of flags/defines for C and C++ files (e.g. -std=c99 and -std=c++14). Obviously, I could invoke Cppcheck twice for C and C++ separately, but in this case I get a bunch of "unusedFunction" false positives.
Any hints are welcome. Thanks in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hmm.. can't you use both --std=c99 --std=c++14? As far as I remember the standard will be chosen depending on file extension. Maybe I am mistaken.
In case you have not seen our --project option I suggest you take a look at that. If it's possible to import a compile database or your build configuration that might be better.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Daniel, Thanks a lot for your tip! I mentioned "--std=c99" and "--std=c++14" just as an example. There are other cases like different defines for C and C++ that I need to pass to the Cppcheck preprocessor in order to allow it properly parse my codebase (for example -DMACRO=VALUE_FOR_CPP and -DMACRO=VALUE_FOR_C). As for the compiledb, unfortunately, that's not an option for me as I work on a deeply embedded project with archaic build system.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not 100% sure but I have the feeling that in the compile commands file you need to use -std with 1 dash.
There are also tools to generate it automatically during compilation. You run "make" or whatever and then those tools will listen on compiler commands and create the compile database. I have used this: https://github.com/rizsotto/Bear and it worked well for me.. but I think that only worked in Linux. There are other tools also.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks again! As I mentioned earlier, I'm working on a project for an embedded target and this project is meant to be crosscompiled (via GCC for ARM and GCC for RISC-V) which means I need to pass to Cppcheck target-specific flags as well (e.g. -D__arm__, -D__thumb__ (and many more) that GCC implicitly adds when compiling for specific targets). Without these flags Cppcheck won't be able to properly parse my codebase (as well as third party sources like CMSIS which detects used compiler.)
Last edit: Andrew 2021-09-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi guys, I've looked through the entire forum for a hint, but didn't find anything similar to my question.
I'm trying to configure Cppcheck to analyze a basic project that contains both C and C++ sources using the "--file-list" option. The problem here is that I need to pass a different set of flags/defines for C and C++ files (e.g. -std=c99 and -std=c++14). Obviously, I could invoke Cppcheck twice for C and C++ separately, but in this case I get a bunch of "unusedFunction" false positives.
Any hints are welcome. Thanks in advance.
hmm.. can't you use both
--std=c99 --std=c++14
? As far as I remember the standard will be chosen depending on file extension. Maybe I am mistaken.In case you have not seen our
--project
option I suggest you take a look at that. If it's possible to import a compile database or your build configuration that might be better.Hi Daniel, Thanks a lot for your tip! I mentioned "--std=c99" and "--std=c++14" just as an example. There are other cases like different defines for C and C++ that I need to pass to the Cppcheck preprocessor in order to allow it properly parse my codebase (for example -DMACRO=VALUE_FOR_CPP and -DMACRO=VALUE_FOR_C). As for the compiledb, unfortunately, that's not an option for me as I work on a deeply embedded project with archaic build system.
you could try to generate the compile database yourself it's just a json file. I assume that something like this works:
I am not 100% sure but I have the feeling that in the compile commands file you need to use
-std
with 1 dash.There are also tools to generate it automatically during compilation. You run "make" or whatever and then those tools will listen on compiler commands and create the compile database. I have used this: https://github.com/rizsotto/Bear and it worked well for me.. but I think that only worked in Linux. There are other tools also.
Thanks again! As I mentioned earlier, I'm working on a project for an embedded target and this project is meant to be crosscompiled (via GCC for ARM and GCC for RISC-V) which means I need to pass to Cppcheck target-specific flags as well (e.g. -D__arm__, -D__thumb__ (and many more) that GCC implicitly adds when compiling for specific targets). Without these flags Cppcheck won't be able to properly parse my codebase (as well as third party sources like CMSIS which detects used compiler.)
Last edit: Andrew 2021-09-11