Error while trying to load a compilation database:

Hi All,

How do I get rid of this error ?

CX08$ /home/phi/llvmbuild/bin/clang-tidy -fix-errors -checks=‘readability-braces-around-statements’ c.c
Error while trying to load a compilation database:
Could not auto-detect compilation database for file “c.c”
No compilation database found in /home/phi or any parent directory
json-compilation-database: Error while opening JSON database: No such file or directory

Thanx in advance

Cheers,

Phi

Hi,

Please, provide more datailed explanation of your issue. Which one of the following is it?

a) You have a compilation database in place and clang-tidy does not detect it.
b) You don’t have a compilation database.

If it’s b) you obviously can get rid of this error by getting a compilation database (on how to refer to Running Clang Tidy on LLVM).

Generally you might not always want to have a compilation database if your goal is just to analyze a single source file: this error doesn’t prevent clang-tidy from inspecting the provided sourcefile, so you’ll still get your diagnostics even if no compilation database is up.

Hope this helps,
Kirill Bobyrev

​Thanx for yout reply.

I am in b) I don’t have a DB.

I red some docco on llvm , I did

CX08$ clang-tidy -dump-config >.clang-tidy

But it didn’t solved anything what I guess is normal .clang.tidy seems to be a configuration file.

I don’t know what is a DB, sonds like I need to run Cmake but I don’t know that at the moment (only know make). I ‘try’ clang-tidy and clang-format, first locally on a couple of files, then later on a bunch of files.

Cheers,

Phi

​So far I understand that Cmake is related with building llvm, while I try to use clang-tidy on my own .c file not related with llvm (located on my login dir)

So I don’t really got it for now.

​Thanx for yout reply.

I am in b) I don't have a DB.

I red some docco on llvm , I did

CX08$ clang-tidy -dump-config >.clang-tidy

But it didn't solved anything what I guess is normal .clang.tidy seems
to be a configuration file.

I don't know what is a DB, sonds like I need to run Cmake but I don't
know that at the moment (only know make). I 'try' clang-tidy and
clang-format, first locally on a couple of files, then later on a bunch
of files.

http://clang.llvm.org/docs/JSONCompilationDatabase.html

As an alternative to using a compilation database, you could also use the `--` flag. Suppose your normal clang command-line was:

   $ clang -fblocks foo.c

Then your clang-tidy command-line would be something like:

   $ clang-tidy foo.c -checks=* -- -fblocks foo.c

Where the set of arguments that go after the `--` is just the same set you would have normally passed to clang.

Jon

​Thanx Jon
It works !! :slight_smile:
One last 'cosmetic' is there a way to have -fix-errors producing another
file instead of trashing the source file, or to have a backup of the
original file, so basically tidy c.c would produce c.c.new and leave c.c
intact OR tidy c.c would backup c.c into c.c.back and patch c.c

I don't remember. I'd check `clang-tidy -help`, or put the relevant source files in version control (or both).

Jon

Hello

I have a question similar to this topic. I am trying to create a compilation data-base using clang and pass it to clang- check.

I created the database using:
clang -MJ compile_commands.json test.c

I then tried passing it to clang-check using:
clang-check test.c

But I get this error:
Could not auto-detect compilation database for file “test.c”
No compilation database found in …

I also tried using:
clang-check -p $PWD test.c

Could you please let me know what I am doing wrong? Is there a way to specify to clang-check which compilation data base to use?

Thanks in advance!

Almost there. From the compilation database docs:
Clang has the ability to generate compilation database fragments via -MJ argument <clang -MJ\<arg>> . You can concatenate those fragments together between [ and ] to create a compilation database.

fragments

Thanks! that worked. It is a bit misleading that the error says that the compilation database could not be detected. Maybe it should say that the file has an invalid format or something to that effect.

But thanks again!