SonarScanner issue: com.sonar.cpp.analyzer.Analyzer$AnalyzerException: Exit code != 0

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarScanner 4.7.0.2747
    Java 11.0.14.1 Eclipse Adoptium (64-bit)
    Windows Server 2019 10.0 amd64
    CFamily plugin version: 6.20.5.49286
    build-wrapper, version 6.20.5 (win-x86-64)
  • what are you trying to achieve
    I want to analyze my C++ CMake project on a Windows machine.
    The same project with a similar SonarQube setup works on a Linux build agent but it fails on the Windows agent with the error shown below.
  • what have you tried so far to achieve this
    I have tried to find strange code in the Dir.cpp file and changed it, but the error is still there.
    I have checked for BOM-headers and looked at that file with a HEX-Editor but could not find any strange stuff.
    I have searched for this error and found similar but different and way older error reports.

I can provide you the sonar-cfamily-reproducer.zip if that helps to find the issue.

com.sonar.cpp.analyzer.Analyzer$AnalyzerException: Exit code != 0: C:\builds\project\source\Module\Dir.cpp
	at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:132)
	at com.sonar.cpp.analyzer.Subprocess.execute(Subprocess.java:52)
	at com.sonar.cpp.plugin.CFamilySensor.lambda$process$8(CFamilySensor.java:733)
	at com.sonar.cpp.analyzer.AnalysisExecutor.lambda$submit$0(AnalysisExecutor.java:59)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
14:22:32.691 ERROR: 
An error occurred while analyzing the following compilation unit: 
  C:\builds\project\source\Module\Dir.cpp
A file named "sonar-cfamily-reproducer.zip" has been generated to help the problem investigation.
Please contact SonarSource support providing the following file to help improving the analyzer:
  C:\builds\project\sonar-cfamily-reproducer.zip
14:22:33.547 INFO: ------------------------------------------------------------------------
14:22:33.547 INFO: EXECUTION FAILURE
14:22:33.547 INFO: ------------------------------------------------------------------------
14:22:33.549 INFO: Total time: 1:43.475s
14:22:33.649 INFO: Final Memory: 29M/120M
14:22:33.649 INFO: ------------------------------------------------------------------------
14:22:33.649 ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: 
An error occurred while analyzing the following compilation unit: 
  C:\builds\project\source\Module\Dir.cpp
A file named "sonar-cfamily-reproducer.zip" has been generated to help the problem investigation.
Please contact SonarSource support providing the following file to help improving the analyzer:
  C:\builds\project\sonar-cfamily-reproducer.zip
	at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:405)
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:177)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:392)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Hi @graf_basti,

Sorry for the late reply.

I sent you a PM where you can share the reproducer.

Thanks,

Thanks for the support.
In short, the issue was that (our) SonarQube does not (yet) understand the MSBuild compiler flags /external, so the /external:I was just ignored and all the important external headers were not found.
I have added a small PowerShell command to replace the external includes (/external:I) in the build wrapper dump by simple includes (/I):

(Get-Content build_wrapper_output_directory\build-wrapper-dump.json).replace('/external:I', '/I') | Set-Content build_wrapper_output_directory\build-wrapper-dump.json

Now the sonar-scanner can happily analyze the code.

Great, it worked!

FYI, these flags are new and weren’t handled in old versions.
This was fixed in the newer SonarQube versions.

To benefit from what @Abbas mentioned, make sure you upgrade to SonarQube v9.9 LTS soon, not only to benefit from our Best LTS Ever™, but because soon we will systematically ask users to upgrade when asking questions about lower versions of SonarQube, which are now considered unsupported. :smiley: