VS Code sonarlint C/C++ compile_commands.json assistance

  • Operating system: Ubuntu
  • IDE name and flavor/env: VS code
  • SonarLint plugin version: v3.4.1
  • Is connected mode used: No
    • Connected to SonarCloud or SonarQube (and which version): No

Hello, I am trying SonarLint setup in VS code for C C++ code. Build mechanism is little complex and I am not from developer background. I need assistance in creating compiler_commands.json file. I tried bear tool, but unfortunately it is creating blank json file. I am able to perform sonar analysis using build wrapper. Compiler used is gcc. I want to know if we can somehow use build wrapper to generate compile_commands.json file.

Any help on this is much appreciated.

Any help is much appreciated.

Thanks.

Hello @rocky,

You can check the ways to generate a compilation database here. The best will depends on your build system: C and CPP Analysis · SonarSource/sonarlint-vscode Wiki · GitHub. For example, if you use CMake, it will be as easy as providing an option to your CMake.

Let me know if none of the approaches work.

Thanks,

Thanks @Abbas, I have tested this but unfortunately it did not help me. Any other way we have? Like using sonarqube build wrapper to extract compilation commands? Or any other tool we can use?

Hello @rocky,

The content of the compilation database is a subset of the content of build-wrapper.json, so we should be able to map from build-wrapper to compilation database. Unfortunately, we dont provide such a script yet.

On the other side you should be able to do it on your own by writing a small script that fits your need. Compilation database has 3 required fields. The directory from which the command is executed. The command that compile your source file and the file that the command compile.

As suggested in the link, writing your own script to generate the compilation database is also possible. I suggest starting by one entry to make sure that the analysis of one file works before investing more time.

Note: feel free to report the maintainer of the bear tool.

Thanks,

Okay. Thanks @Abbas for the inputs.

Hello @rocky,

Do you need more help on the topic ? Or could I close this thread ?

We can close this thread.