Hello,
I am trying to analyze with SonarQube a C program written using Visual Studio 2022 IDE.
In my development environment I have added the Clang Power Tools extension in order to generate the compilation database (compile_commands.json file) and the sonarlint extension for Visual Studio run smoothly without problems.
The problem arise when I push the “solution” on my GitLab server that is integrated with the SonarQube server (Developer Edition). During the execution of the CI I got:
ERROR: Error during SonarScanner execution
[187](https://git.xxx.it/danilo/Solution/-/jobs/215#L187)java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
[188](https://git.xxx.it/danilo/Solution/-/jobs/215#L188) * you are correctly invoking the scanner with correct configuration
[189](https://git.xxx.it/danilo/Solution/-/jobs/215#L189) * your compiler is supported
[190](https://git.xxx.it/danilo/Solution/-/jobs/215#L190) * you are providing the path to the correct Compilation Database JSON
[191](https://git.xxx.it/danilo/Solution/-/jobs/215#L191) * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
[192](https://git.xxx.it/danilo/Solution/-/jobs/215#L192) at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:494)
[193](https://git.xxx.it/danilo/Solution/-/jobs/215#L193) at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:186)
The GitLab server and the GitLab agent used to execute the CI (as shell command, not using docker) are installed on a Ubuntu machine and all stuff updated to the latest version.
Here is a snippet of compile_commands.json:
{
"directory": "C:/Users/<edited>/Desktop/Solution/",
"command": "\"C:/Users/<edited>/AppData/Roaming/ClangPowerTools/LLVM_Lite/Bin/clang++.exe\" -x c \"C:/Users/<edited>/Desktop/Solution/Solution/main.c\" -Wall -fms-compatibility-version=19.10 -Wmicrosoft -Wno-invalid-token-paste -Wno-unknown-pragmas -Wno-unused-value -m32 -fsyntax-only \"-DUNICODE\" \"-D_UNICODE\" \"-D_MT\" \"-D_DLL\" \"-D_CRT_SECURE_NO_WARNINGS\" \"-DWIN32\" \"-DNDEBUG\" \"-D_LIB\" \"-D_CRT_SECURE_NO_WARNINGS\" \"-D_DEBUG_FUNCTIONAL_MACHINERY\" -isystem\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/include\" -isystem\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/atlmfc/include\" -isystem\"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/VS/include\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/ucrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/um\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/shared\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/winrt\" -isystem\"C:/Program Files (x86)/Windows Kits/10/Include/10.0.19041.0/cppwinrt\"",
"file": "C:/Users/<edited>/Desktop/Solution/Solution/main.c"
}
Here is a snippet of sonar-project.properties:
sonar.sources=Solution
sonar.cfamily.compile-commands=compile_commands.json
sonar.cfamily.threads=3
sonar.cfamily.cache.enabled=false
The .gitlab-ci.yml is a quite simple script where sonar-scanner is invoked using:
sonarqube-check:
tags:
- shell
stage: test
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
GIT_DEPTH: "0"
FF_ENABLE_JOB_CLEANUP: 1
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- /opt/sonar-scanner/bin/sonar-scanner -Dsonar.projectVersion=${CI_COMMIT_BRANCH}
allow_failure: true
only:
- main
Product versions list:
- SonarQube: Developer Edition Version 9.4 (build 54424)
- sonar-scanner: 4.7.0.2747
- Visual Studio 2022: 17.2.1
- SonarLint for Visual Studio 2022: 6.4.1.47693
- Clang Power Tools 2022: 8.7.0.569
Someone have any idea how to solve this problem?
Thank in advance…
Danilo