3

I'm practising clean code and I installed sonarlint as a static testing tool to help me write clean code. after installing the editor rises this notification

SonarLint is unable to analyze C and C++ file(s) because there is no configured compilation database.

after some searching, I found that I should add a file with a name

compile_commands.json.

this file should be exported automatically by cmake after adding this option

CMAKE_EXPORT_COMPILE_COMMANDS

where can I add this option in VScode.

this link is where the vscode redirected me to creat the required .json file

ayman magdy
  • 63
  • 1
  • 7
  • I'm pretty sure that if you invoke the cmake configure command via vs code, it automatically requests this to be set as a cache variable via command-line. look under your binary directory for the file. – starball Sep 02 '22 at 17:48
  • Also, from [the docs](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html): "_Note: This option is implemented only by Makefile Generators and the Ninja. It is ignored on other generators._". Are you using one of the supported generators? Ex. Visual Studio doesn't support this. – starball Sep 02 '22 at 17:50

1 Answers1

1

I am assuming that you are using CMake for your build. If that is the case then add the following line to the CMakeLists.txt

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Then build the project and the database will be created for you.