SonarLint giving '0 compilation units analyzed' with standard compile_commands.json

Please provide

  • Operating system: Windows 10 64bit
  • SonarLint plugin version: v4.4.2
  • Programming language you’re coding in: C++
  • Is connected mode used: Yes and No, tried with both, currently just trying to use SonarLint locally
    • Connected to SonarCloud or SonarQube (and which version): SonarQube Enterprise Edition Version 10.4.1

And a thorough description of the problem / question:

Hi!

I am trying to analyze a project using SonarLint and no problems are detected. The project has a custom build system, but I made a script that generates the correct compile_commands.json, that I feed into SonarLint.

The problem is, even with the highest level of verbosity, the vscode output for SonarLint shows this:

[Debug - 11:02:09.986] Execute Sensor: CFamily
[Info - 11:02:09.996] Parsing compilation database C:\source\directory\compile_commands.json
[Debug - 11:02:10.285] Time to parse Compilation Database: 295ms
[Info - 11:02:10.285] Subprocess(es) done in 298ms
[Info - 11:02:10.285] 0 compilation units analyzed
[Info - 11:02:10.285] Found 0 issues

What I assume must be the problem is the ‘0 compilation units analyzed’, showing that the file isn’t perceived as a compilation unit?..

My compile_commands.json structure:

[
{
"directory": "absolute\\path\\to\\directory",
"command": "absolute\\path\\to\\compiler <compiler arguments separated by space>",
"file": "absolute\\path\\to\\file",
"output": "absolute\\path\\to\\.o\\file"
},
{
"directory": "absolute\\path\\to\\directory",
"command": "absolute\\path\\to\\compiler <compiler arguments separated by space>",
"file": "absolute\\path\\to\\file",
"output": "absolute\\path\\to\\.o\\file"
},
...
]

Question 1: Is there a specific format required for the compile_commands.json on windows? I tried with both forward slashes ‘/’ and double backslashes ‘\’ for the paths and command, but no luck. The command works as expected when executing from a clean cmd and no environment variables are required.

Question 2: Is there any requirement for the compiler to be used? I tried the QNX compiler and the i686-w64-mingw32-gcc compilers, each with their respective arguments.

Hello @iustin05,

Can you share the actual compile_commands.json and the full logs of SonarLint? If you don’t want to make them public, I can send you a private message.

1 Like

Hi and thanks for the reply!

Please send me a message :slight_smile:

The issue was fixed.

For anyone bumping into the same problem, when generating the compile_commands.json, keep in mind that the “directory” entry for each compilation unit is actually the current working directory that you use to execute your compilation commands, not the directory of the target file itself.

So if, for example, you run your command from C:/project1, and the target file is C:/project1/directory1/CFile.cpp, your json entries should look like this:

{
"directory": "C:/project1",
"command": "<your exact and complete command>",
"file": " C:/project1/directory1/CFile.cpp"
}

Good reading: LLVM JSON Compilation Database

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.