0

I need to check 2 million C source files for a research project for simple syntax errors like missing (semicolons, parenthesis, ...). Each file is a function without main() and header files. With the help of GCC, I have used the following command:

gcc -c -fsyntax-only -w file.c

My script is doing the job, but the only problem is that almost more than 95% of errors are related to missing header files. I tried to add some of these header files to each function, but the number of these header files seems endless.

Is there any way to suppress errors about missing header files?

Does GCC have a special Flag that I can use for my purpose?

A sample of errors that are related to header files:

error: unknown type name ‘ioreq_t’
error: unknown type name ‘SH7750State’
error: unknown type name ‘int64_t’
error: unknown type name ‘AVCodecContext’
error: unknown type name ‘BlockDriverState’
error: unknown type name ‘PXA2xxLCDState’

Also, I appreciate any other solution besides using GCC.

Chelsea-fc
  • 145
  • 7
  • 4
    If the header files can't be found, then how can the compiler use any of the stuff defined in those headers? Not sure what you're looking to achieve, here. – Adrian Mole Jun 20 '22 at 08:38
  • 2
    with missing headers it isnt possible in general to check syntax. Suppose there is a `foo{bar}`. Without a declaration of `foo` how would you know if the syntax is correct? – 463035818_is_not_an_ai Jun 20 '22 at 08:38
  • 1
    Of course not. You can't suppress errors. Your question doesn't make sense. – user207421 Jun 20 '22 at 08:38
  • 2
    Who made "2 million C source files" that aren't compilable? – Caleth Jun 20 '22 at 08:42
  • 2
    I recommend to remove the `c++` tag if you are only interested in C sources. Here is a somewhat related question: https://stackoverflow.com/questions/27714891/is-it-possible-to-get-lexer-output-from-gcc-or-clang – chtz Jun 20 '22 at 08:46

1 Answers1

7

As workaround, you might create one header which includes all the missing #include and use -include to force that inclusion on top of examined files. So you don't edit all files:

gcc -include "workaround.h" -c -fsyntax-only -w file.c
Jarod42
  • 203,559
  • 14
  • 181
  • 302