9

I am compiling a fairly large library with many outside dependencies that I need to pull in. Each time I attempt a compilation I get a new error about a missing header file. I then have to go and track down where to find that header/library and add it to the project includes. This process of compilation-then-find-header/source is repeated and takes a lot of time.

I would like the compiler to continue trying to build and output all missing headers in one error list. Is this possible using Clang and if so how can I control it? On a related note, once I have all headers is it possible to tell Clang to report all linker errors/undefined references, so I don't have to repeat this process with source files?

I am looking for compiler flags to print out all possible errors (missing headers) and all undefined references. In other words, I want the compilation to continue passed the first file with errors and attempt to compile all files in the project. The compiler is Clang (C/C++) version 8.0.2. The make tool is ninja (1.5.3). Make files are generated with CMake (3.6.4).

Update: Looking back, my original question was asking for a solution in the wrong tool. Instead of passing a flag to Clang, I needed to pass a flag to my make tool, Ninja.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
javey
  • 374
  • 4
  • 12
  • `-Weverything` will give you *all* warnings with clang - even the silly ones. `-Werror` will turn all warnings into errors. You could have found that out yourself by reading the compilers documentation (but I guess noone reads documentation these days).. – Jesper Juhl Nov 18 '19 at 18:35
  • 3
    @JesperJuhl I think OP asks how to make Clang not stop on the first missing header error. – HolyBlackCat Nov 18 '19 at 18:37
  • 2
    https://clang.llvm.org/docs/UsersManual.html#cmdoption-ferror-limit The error limit flag might help you with seeing more errors. But it may not be what you're asking for. As you fix errors, the build process will progress further and potentially find more errors. – Larry B Nov 18 '19 at 18:42
  • 4
    Are you using `make` to build? If so, you're not asking for an option to clang but for make. Then you might like to add the option `-k` to make it "keep going" to compile every source and not stop after the first with a warning/error. – the busybee Nov 18 '19 at 21:25
  • Which language, C or C++? They are distinct languages. For example, C++ has the `` header file and C doesn't. – Thomas Matthews Nov 18 '19 at 22:38
  • 1
    Thanks for the comments. I didn't realize this could potentially be solved with a flag to the make tool. I've updated the question to hopefully clarify that I'm looking to attempt a build of all files in the project (not stop on first file with errors). I've also added my make tool information. – javey Nov 19 '19 at 19:29
  • 1
    Looks like I found what I was looking for: ```ninja -k 0``` – javey Nov 19 '19 at 20:14
  • If you are using ```make``` then the equivalent would be ```make -k```, as @2785528 and @the busybee pointed out. – javey Nov 19 '19 at 20:21

1 Answers1

13

From ninja --help:

-k N     keep going until N jobs fail [default=1]

so i'd run ninja command like:

ninja -k 100

to continue until 100 errors are found or the build succeeds. One thing to note is that some errors may just stop the entire build if the erroneous file is necessary to continue the build process.

A. K.
  • 34,395
  • 15
  • 52
  • 89