Ranjit
Ranjit

Reputation: 51

How do I get SonarQube Scanner to analyze C and C++ code?

I am running the community edition of SonarQube 7.1 on RHEL 7.x. When I run sonar-scanner -X, I see the output on the backend like this:

hello.py indexed with language 'py'
hello.java indexed with language 'java'
hello.cpp indexed with language 'null'
hello.c indexed with language 'null'

I expected to see "indexed with language cpp" and "indexed with language c".

When I go to the web UI, see the hello.py and hello.java in the project directory. But I see no reference to the .cpp or .c code. I expect to see the .c and .cpp files in the web UI. This has never worked, so let me give some background on what I did.

To install the plugin for the .cpp and .c code, I downloaded a .zip file with the highest version number. I initially tried to find it on the local SonarQube installation, but the URL "http://localhost:9000/static/cpp/build-wrapper-linux-x86.zip" (and its derivatives for my own deployment) did not work for me. As a side note, I am curious if there are alternative paths and why this path would lead to 404 or "No page can be displayed" messages in my web browser.

After I unzipped the plugin for C++ and C, I ran (from the command prompt): build-wrapper-linux-x86-64 --out-dir bw_output make

I also ran (from the command prompt): build-wrapper-linux-x86-64 --out-dir bw_output make sonar-scanner

Both ran without errors. It appears that SonarQube is not analyzing .c or .cpp source code. I base this off two things. One, the lack of output in the web UI when other files are analyzed in the same directory. Two, the output on the backend referring to language 'null' for .c and .cpp files. What am I doing wrong in configuring SonarQube to analyze C and C++ code?

Upvotes: 3

Views: 7933

Answers (2)

George312
George312

Reputation: 27

Alternative for SonarCFamily is sonar-cxx plugin

but as far as i know it can only analyse with the result of other static/dynamic tools. I have used with Valgrind, Dr.Memory, Bullseye.

Upvotes: 0

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22804

You say you downloaded SonarCFamily and exploded the jar. This was not what you wanted to do. Instead, you should have installed the intact jar in $SONARQUBE_HOME/extensions/plugins. Then the download URL would have worked for you, and your analysis would have recognized and provided rules for your C files.

However, SonarCFamily is not one of the free code analyzers. It comes as part of Developer Edition($), for which a paid license is required.

Upvotes: 2

Related Questions