Not able to get analysis results for C++

I am trying to get C++ scans working with SonarQube developer edition. Every other language works fine so far. When I scan a built C++ package, I get these results:

log.txt (43.9 KB)

cppcode sonar-scanner -X \
  -Dsonar.projectKey=cpp_bre \
  -Dsonar.sources=. \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.login=386b134f8701eeea0a3abcac0d7d22fc842dbfe7 -Dsonar.cfamily.build-wrapper-output=build_wrapper_output_directory > log.log
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/Users/etew/.sonar/cache/a89f1943fc75b65becd9fb4ecab8d913/sonar-tsql-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
14:24:57.857 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
  * you are using the latest version of the build-wrapper and the SonarCFamily analyzer
  * you are correctly invoking the scanner with correct configuration  * your compiler is supported
  * you are wrapping your build correctly
  * you are wrapping a full/clean build
  * you are providing the path to the correct build-wrapper output directory
	at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:255)
	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:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	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)

I have attached a full log of the output. The build was done using the linux version of the build scanner. I’m running developer version 8.1 (build 31237)

Hello @etew,
Welcome to the community!

Are you running the build-wrapper before running the scanner?
If not please check Cfamily documentation to know how to do it.
Let me know if it works.

Thanks,
Abbas

I meant to say:

The build was done using the linux version of the build wrapper.

Not scanner. So yes it is.

@etew what compiler are you using?

I am using g++

@etew:

  • You are on Cfamily 6.5 please update to 6.7 and check if the error is still reproducable.

  • Are you passing to the build-wrapper a full build command? Incremental build is not currently supported.

If both points don’t fix the issue, please share with me the build-wrapper log and json files. You can share them privately if they contain sensitive information.

How do I get the new version? The version of sonarqube developer edition I downloaded contained sonarcfamily 6.5 and I am not able to find a download link for just sonarcfamily.

I am just running “build-wrapper-linux-x86-64 --out-dir build_wrapper_output_directory make”

Also, I am unclear about what an incremental build is. I believe the build I am trying to scan is multi-stage.

@etew,

  • build wrapper needs a full clean build. Try to do build-wrapper-linux-x86-64 --out-dir build_wrapper_output_directory make clean all

  • To update your plugin you should go to AdministrationMarketplace

I updated SonarCfamily and all the plugins I use, ran make clean all, and got the same result.

If I cannot get SonarCFamily to scan, are there any supported opensource plugin alternatives I could use to import C++ results into SonarQube?

@etew can you share the requested files so I can figure out what is going wrong?

Right now I am running the build on a Linux build node, copying the folder to my Mac, then running Sonar Scanner on my Mac and placing the . Could this be causing issues? I got a similar error when scanning and building on the same node, but am not doing so currently.

@etew,

Definitely, they should run on the same machine. From the Documentation:

NB: The Build Wrapper collects information about the build including absolute file paths (source files, standard headers, libraries, etc…). Later on, SonarScanner uses this information and needs to access those paths. Whereas this is straightforward while running these 2 steps on the same host, it is worth some consideration when using any sort of containerization like Docker.

Please reproduce the issue while building and scanning on the same machine and share the requested log so i can help you.

Thanks,

I was able to get it to scan. Thanks for the help!