C++ project with buildwrapper SonarScanner failure 'libz.so.1: cannot open shared object file: No such file or directory' error

Java 11.0.5 Alpine (64-bit)
Linux 5.4.0-1056-aws amd64
CFamily plugin version:

We’re trying to scan a C++ project but we’re facing a shared library can not be opened error.
The C++ files are being indexed and the build-wrapper seems to be working ok and producing output.

09:21:35.464 DEBUG: Probing compiler: [/usr/bin/x86_64-linux-gnu-g+±9, -x, c++, --std, gnu++17, -v, -dM, -E, -]

…/.scannerwork/.sonartmp/8153199736344520861/subprocess: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

We’ve confirmed that the libz.so.1 file is present under /lib and that LD_LIBRARY_PATH=/lib, however, the scanner is still unable to open the file. Any ideas?

Hi @Masu_Elma ,

how are you running your analysis? Are you running sonar-scanner inside an alpine docker container?

Please note that build and analysis should be run within the same environment.

Yes, the scanning is performed in an Alpine docker container. So just to be clear, you are saying that both the build stage (where the build-wrapper is produces output) and the scanning step must be carried out within the same docker container?

Hi @Masu_Elma ,

yes, the analyzer needs to access the files used during the build, system headers and third-party headers are needed to have a good analysis. You can read the documentation page related to C and C++: https://docs.sonarqube.org/latest/analysis/languages/cfamily//