How to do a C++ code analysis

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

Sonarqube 10.5.1
SonarScanner CLI
Java 17.0.1 Red Hat, Inc. (64-bit)
Linux 6.5.0-35-generic amd64

  • how is SonarQube deployed: zip, Docker, Helm


  • what are you trying to achieve

C++ code analysis

  • what have you tried so far to achieve this

I’m trying to follow this guide: C/C++/Objective-C

When I execute:


I get this output:

08:31:41.756 INFO  Scanner configuration file: /sonar-scanner/sonar-scanner-
08:31:41.759 INFO  Project root configuration file: /program1build/
08:31:41.770 INFO  SonarScanner CLI
08:31:41.772 INFO  Java 17.0.1 Red Hat, Inc. (64-bit)
08:31:41.773 INFO  Linux 6.5.0-35-generic amd64
08:31:41.797 INFO  User cache: /root/.sonar/cache
08:31:42.623 INFO  Total time: 0.866s
08:31:42.624 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Failed to get server version
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(
	at org.sonarsource.scanner.cli.Main.analyze(
	at org.sonarsource.scanner.cli.Main.main(
Caused by: java.lang.IllegalStateException: Call to URL [https://sonarqube.example.local/api/v2/analysis/version] failed
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callUrl(
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callApi(
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callRestApi(
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(
	... 3 common frames omitted
Caused by: Failed to connect to sonarqube.example.local/
	at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:297)
	at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:207)
	at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226)
	at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
	at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
	at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.kt:221)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
	at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callUrl(
	... 6 common frames omitted
Caused by: Connection refused
	at java.base/ Method)
	at java.base/
	at java.base/
	at java.base/
	at java.base/
	at java.base/
	at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:128)
	at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:295)
	... 24 common frames omitted
08:31:42.631 ERROR 
08:31:42.631 ERROR Re-run SonarScanner CLI using the -X switch to enable full debug logging.

Hey there.

  • Can you confirm that, for example, you can access SonarQube at this address in a web browser on the same machine you’re running the analysis? https://sonarqube.example.local
  • Can you try DEBUG level analysis and provide the logs? sonar-scanner -X

I tried to analyze again with -X option and the output said that credentials are wrong. Then I added username and password into and now I’m getting the following error:

06:21:43.765 INFO  Analysis total time: 43.006 s
06:21:43.766 INFO  Total time: 46.890s
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: ch/qos/logback/classic/spi/ThrowableProxy
	at ch.qos.logback.classic.spi.LoggingEvent.<init>(
	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(
	at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(
	at ch.qos.logback.classic.Logger.error(
	at org.eclipse.jgit.internal.util.ShutdownHook.cleanup(
	at java.base/
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.spi.ThrowableProxy
	at java.base/
	at org.sonarsource.scanner.lib.internal.IsolatedClassloader.loadClass(
	at java.base/java.lang.ClassLoader.loadClass(
	... 6 more

This time it looks like everything might have worked just fine, and you’re facing a messy log issue we’ll fix with SonarQube v10.6.

Do you see your analysis on SonarQube?

Oh I’ve just noticed. The project was actually created in my Sonarqube dashboard.

But I guess I need to hustle a little more. Currently Sonarqube says only “The main branch has no lines of code.”

Sadly I can’t figure out this issue. Output from sonar-scanner seems reasonable, but I don’t understand why Sonarqube thinks the project has no lines of code.

Sharing the DEBUG scanner logs (sonar-scanner -X) here might help somebody help you!

I figured it out. I wasn’t paying close attention to the actual logs. I had to add the following settings:

Finally after resolving the upload limit issue on the server side I got the code into SQ dashboard.

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