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 6.0.0.4432
Java 17.0.1 Red Hat, Inc. (64-bit)
Linux 6.5.0-35-generic amd64

  • how is SonarQube deployed: zip, Docker, Helm

Zip

  • 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:

sonar-scanner

I get this output:

08:31:41.756 INFO  Scanner configuration file: /sonar-scanner/sonar-scanner-6.0.0.4432/conf/sonar-scanner.properties
08:31:41.759 INFO  Project root configuration file: /program1build/sonar-project.properties
08:31:41.770 INFO  SonarScanner CLI 6.0.0.4432
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.619 INFO  EXECUTION FAILURE
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(ScannerEngineBootstrapper.java:147)
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:111)
	at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:63)
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(ServerConnection.java:172)
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callApi(ServerConnection.java:143)
	at org.sonarsource.scanner.lib.internal.http.ServerConnection.callRestApi(ServerConnection.java:121)
	at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:142)
	... 3 common frames omitted
Caused by: java.net.ConnectException: Failed to connect to sonarqube.example.local/192.168.4.87:443
	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(ServerConnection.java:170)
	... 6 common frames omitted
Caused by: java.net.ConnectException: Connection refused
	at java.base/sun.nio.ch.Net.pollConnect(Native Method)
	at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
	at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:549)
	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)
	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	at java.base/java.net.Socket.connect(Socket.java:633)
	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 sonar-project.properties and now I’m getting the following error:

...
06:21:43.765 INFO  Analysis total time: 43.006 s
06:21:43.765 INFO  EXECUTION SUCCESS
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>(LoggingEvent.java:145)
	at ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:424)
	at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:386)
	at ch.qos.logback.classic.Logger.error(Logger.java:543)
	at org.eclipse.jgit.internal.util.ShutdownHook.cleanup(ShutdownHook.java:87)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.classic.spi.ThrowableProxy
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
	at org.sonarsource.scanner.lib.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 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:

sonar.branch.name=mybranch
sonar.scm.exclusions.disabled=true
sonar.filesize.limit=100

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.