SonarLint is unable to analyze C and C++ file(s) because there is no configured compilation database

Please provide

  • Operating system: Windows 10 Pro 21H2
  • IDE name and flavor/env: VScode
  • SonarLint plugin version:3.5.4
  • Is connected mode used:Nope
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

I got the error “SonarLint is unable to analyze C and C++ file(s) because there is no configured compilation database.” in version 3.5.4.
I am sure it’s not cause by my system or settings cause it got fixed in version 3.5.3.
Moreover, I was just coding in C and it’s been no error pop up before I hit the reload button.

Hi @Henry1 ,

can you make sure that you select a valid compilation database?

If I select it manually it will show “No compilation databases were found in the workspace”

I’m confuse about why is the older version running great under the same settings.

Hello @Henry1.

Sorry answer took so long.
Can you please double check the versions that you mentioned. Is it possible that working version is not 3.5.3, but something earlier? SonarLint updates automatically and you could miss that.
I’m asking because difference between this two versions you mentioned is one ticket, and I’m not sure how it could break C/C++ analysis. But we changed it in previous several versions.
Also would be great if you provided small reproducer project or code sample so we could investigate.

I’m sure it’s 3.5.3. Because after I got this issue, I manually downgraded to version 3.5.3. And now It works great. I didn’t change any other settings either.

Thanks for the fast response.

OK, for 3.5.4 we changed only one thing - how we get opened file URI. And for general cases it’s working. Is there something odd in the path to your project or file names? Rare characters for example, network disks or this kind of things? Path I can see on the screenshot is perfectly fine.

C:\Users\henry\OneDrive\Programs\Program\C_C++\C\1.c
This is my path. A cool thing is that the 3.5.4 is working on my workstation PC and mac mini but not on my Mac or windows laptop. Every Laptop needs to be in 3.5.3.

Looks really strange. We will try to think about possible reasons, but if you will find something that differ your laptops from workstations please get back here. It will really help.

The last 3.4.1 → 3.5.3 version had the same problem too. There’s a way to fix it. I moved all the files out and put them into a new folder and it worked. I’m still working on something so haven’t tried it this time.

Just want to let you know that the issue is still unsolved in the latest update.

Hello @Henry1.
Can you please provide full logs for this issue, and ideally reproducer sample project?

Executing /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/jre/17.0.3-macosx-aarch64.tar/bin/java -jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/server/sonarlint-ls.jar 50219 -analyzers /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarjava.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarjs.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarphp.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarpython.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarhtml.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarxml.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarcfamily.jar -extraAnalyzers /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/analyzers/sonarsecrets.jar
[stdout] Binding to 50219
Child process connected on port 50219
Java resolved to: /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.7.0-darwin-arm64/jre/17.0.3-macosx-aarch64.tar
[Info  - 00:07:36.368] Started security hotspot handler on port 64120
Initializing file:///Users/henry/OneDrive/Programs/Program on branch undefined
[Debug - 00:07:36.408] Fetching global configuration
[Debug - 00:07:36.411] Folder file:///Users/henry/OneDrive/Programs/Program is now on an unknown branch.
[Debug - 00:07:36.413] Queuing analysis of file 'file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/1.cpp' (version 1)
The 'file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/1.cpp' file is not in a git repo, consider as not ignored
[Debug - 00:07:36.416] Cached SCM ignore status for file 'file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/1.cpp': Not ignored
[Debug - 00:07:36.420] Fetching configuration for folder 'file:///Users/henry/OneDrive/Programs/Program'
[Debug - 00:07:36.423] Skipping analysis of C and C++ file(s) because configured compilation database does not exist: 
[Debug - 00:07:36.425] Workspace folder 'WorkspaceFolder[name=Program,uri=file:///Users/henry/OneDrive/Programs/Program]' configuration updated: WorkspaceFolderSettings[analyzerProperties={},connectionId=<null>,pathToCompileCommands=,projectKey=<null>,testFilePattern=]
[Debug - 00:07:36.425] Global settings updated: WorkspaceSettings[connections={},disableTelemetry=true,excludedRules=[java:S106],includedRules=[],pathToNodeExecutable=,ruleParameters={},showAnalyzerLogs=false,showVerboseLogs=true]
[Debug - 00:07:36.433] Default settings updated: WorkspaceFolderSettings[analyzerProperties={},connectionId=<null>,pathToCompileCommands=,projectKey=<null>,testFilePattern=]
[Debug - 00:08:46.587] Fetching global configuration
[Debug - 00:08:46.589] Fetching configuration for folder 'file:///Users/henry/OneDrive/Programs/Program'
[Debug - 00:08:46.590] Global settings updated: WorkspaceSettings[connections={},disableTelemetry=true,excludedRules=[java:S106],includedRules=[],pathToNodeExecutable=,ruleParameters={},showAnalyzerLogs=true,showVerboseLogs=true]
[Debug - 00:09:51.437] Queuing analysis of file 'file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/aa123.cpp' (version 1)
The 'file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/aa123.cpp' file is not in a git repo, consider as not ignored
[Debug - 00:09:51.438] Cached SCM ignore status for file 'file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/aa123.cpp': Not ignored
[Debug - 00:09:51.438] Skipping analysis of C and C++ file(s) because configured compilation database does not exist: 

sorry for the late reply.
These are the logs from 3.7.0

Executing /usr/bin/java -jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/server/sonarlint-ls.jar 50470 -analyzers /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarjava.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarjs.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarphp.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarpython.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarhtml.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarxml.jar /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarcfamily.jar -extraAnalyzers /Users/henry/.vscode/extensions/sonarsource.sonarlint-vscode-3.5.3/analyzers/sonarsecrets.jar
[stdout] Binding to 50470
Child process connected on port 50470
Java resolved to: /usr
[Info  - 00:12:11.321] Started security hotspot handler on port 64120
Initializing file:///Users/henry/OneDrive/Programs/Program on branch undefined
[Debug - 00:12:11.348] Fetching global configuration
[Debug - 00:12:11.349] Folder file:///Users/henry/OneDrive/Programs/Program is now on an unknown branch.
[Debug - 00:12:11.351] Skipping analysis for preview of file file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/1.cpp
[Debug - 00:12:11.359] Fetching configuration for folder 'file:///Users/henry/OneDrive/Programs/Program'
[Debug - 00:12:11.363] Workspace folder 'WorkspaceFolder[name=Program,uri=file:///Users/henry/OneDrive/Programs/Program]' configuration updated: WorkspaceFolderSettings[analyzerProperties={},connectionId=<null>,pathToCompileCommands=,projectKey=<null>,testFilePattern=]
[Debug - 00:12:11.363] Global settings updated: WorkspaceSettings[connections={},disableTelemetry=true,excludedRules=[java:S106],includedRules=[],pathToNodeExecutable=,ruleParameters={},showAnalyzerLogs=true,showVerboseLogs=true]
[Debug - 00:12:11.369] Default settings updated: WorkspaceFolderSettings[analyzerProperties={},connectionId=<null>,pathToCompileCommands=,projectKey=<null>,testFilePattern=]
[Debug - 00:12:17.960] Skipping analysis for preview of file file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/aa123.cpp
[Debug - 00:12:21.047] Synchronizing storage
[Debug - 00:12:24.336] Skipping analysis for preview of file file:///Users/henry/OneDrive/Programs/Program/C_C%2B%2B/C%2B%2B/C1_1.cpp

These are the logs from 3.5.3, which can run with no issue.

Hello @Henry1,

Sorry for the late reply. So the problem is that:
[Debug - 00:09:51.438] Skipping analysis of C and C++ file(s) because configured compilation database does not exist:

Looks like you have the wrong path to compilation database in your project. I guess you need to fix the path to the correct one and it should work.

Do you have any idea or hint as to what to change?
Because I didn’t change anything besides the SonarLint version.

Can you check the .vscode folder in your project? The sonarlint.pathToCompileCommands property in the settings.json file. The value should be the valid path on your machine.

There’s no .vscode folder in my project because it will crash everything in it.
But everything works fine.
I’ll try for more solutions, thanks for your help!

You can also find details on how to configure the compile database on this wiki page.

Please try these steps to configure easily: SonarLint for C/C++ with Makefile support on VS-Code | Medium