Sonarlint: Configure the compilation database for C++

Please provide

  • Operating system: Linux
  • SonarLint plugin version: v3.17.0
  • Programming language you’re coding in: C++
  • Is connected mode used: No
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

Hi Team,

I am developing C++ modules and these modules generates /build/compile_commands.json file but these commands in that file works only on the docker container which is spinned after building the code so solarlint is not able to detect and analize C++ files and suggest realtime fixes as it should do locally …
Is there a solution for such an issue ?

Sample of compile_commands.json

{
  "directory": "/tmp/app_dir/build/amd64/service",
  "command": "/usr/bin/c++  -DLOG_DEBUG_BUILD -I/tmp/app_dir/build/amd64/service/autogen/public -I/tmp/app_dir/build/amd64/service/autogen/src -isystem /opt/csp/hpsdk/amd64/include/csp -isystem /opt/csp/hpsdk/amd64/include -isystem /opt/csp/hpsdk/amd64/include/csp/sfw  -g -O0 -fno-aggressive-loop-optimizations -fvisibility=hidden -Wall -Wextra -Wpedantic -Wno-error=deprecated-declarations -std=c++14 -fvisibility-inlines-hidden -D_POSIX_C_SOURCE=200112L  -O0 -DNDEBUG   -o CMakeFiles/seatmanager_proxy_target.dir/autogen/src/seatmanager_proxy.cpp.o -c /tmp/app_dir/build/amd64/service/autogen/src/seatmanager_proxy.cpp",
  "file": "/tmp/app_dir/build/amd64/service/autogen/src/seatmanager_proxy.cpp"
},

Thanks
Ziad Khater

Reproducing the issue in SonarLint.gif - Google Drive

Issue solved by updating the paths in compile_commands.json to match local paths.

1 Like

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