SonarLint unable to find any C++ headers

Please provide

  • Operating system: Ubuntu 22.04
  • IDE Version: CLion 2023.2.2
  • SonarLint plugin version: 10.0.0.76954
  • Programming language you’re coding in: C++
  • Is connected mode used: Yes
    • Connected to SonarCloud or SonarQube (and which version): SonarQube Enterprise Edition
      *** Version 9.9.2 (build 77730)**

And a thorough description of the problem / question:

Hey all, I have configured SonarLint w/ CLion for a project using the docker toolchain. I am able to connect to the SonarQube server just fine, but none of the local header files in my project are found by SonarLint. The project builds just fine.

I suspect it has something to do with the top level CMakeLists.txt not being at the same level as the SonarQube project. We have a setup like this

Repo/
  - Main/
    - CMakeLists.txt
    - ...
  - Foo/
  - Bar/

And my CLion CMake project uses the CMakeLists.txt in Main/ as the root CMakeLists.txt file. There is no top level CMakeLists.txt file in Repo/.

But on SonarQube it seems like we also do analysis on the Foo/ and Bar/ folders as well as Main/ meaning it must be pointing to Repo/.

End result in my IDE is that SonarLint is unusable because there are so many major code smells found related to erroneous file not found, unknown type, and undeclared identifiers, etc.

I tried digging through settings but I haven’t found anything I could leverage to test my hypothesis.

Hi @maspe36,

Could you please share your SonarLint logs with us, after doing an analysis on one of the files triggering the wrong result? You can check this documentation on how to get SonarLint logs.

Thank you

Hey!

Unfortunately, I don’t think I can share these logs. I collected them, but after looking over them they do expose a bunch of things about my employers code structure (understandably so).

So please bear with me as I try to extract useful information without actually sharing the logs directly :smiley:

The extraProperties tag in the analysis configuration JSON is pointing to a local path (/home/user/src/Repo/my/code/header.h), but all of the -I includes to the compiler are using the docker path (-I/app/Repo/my/code/).

We mount a folder above our repo into a docker container when we build (/home/user/src//app/). The CLion docker toolchain handles this for us (see here).

So it actually seems like the problem is a mismatch in local path input files but includes that use the docker path.

"cmd":[
"/usr/bin/g++",
"/home/user/src/Repo/my/code/header.h",
"-I/app/Repo/my/code/"
]

Should be easy to reproduce by just using the Docker Toolchain.

Hi @maspe36 ,

thank you for your report. I was able to reproduce the issue. It is related to CPP-4039.

We are going to work on a fix. While waiting for it would you be able to either use a local or a remote toolchain?

Awesome, glad this is being tracked!

use a local or a remote toolchain?

Unfortunately our build environment isn’t so flexible. I’ll just need to wait for CPP-4039 to be fixed.

Thanks all :slight_smile:

1 Like