How can I run clang scan-build on this Cmake project?
Opened this issue · 4 comments
The internet seems to claim that I can do the following:
$ export CC=/usr/bin/clang
$ export CXX=/usr/bin/clang++
$ scan-build cmake ...
$ cd build_sdl_sim
$ scan-build make
However, this doesn't work in two different ways.
First, cmake (or perhaps our usage of cmake) does not seem to honor CC and CXX. Instead, it invariable uses /usr/bin/cc
On my system, /usr/bin/cc is a symlink to /etc/alternatives/cc, which is a symlink to /usr/bin/gcc
I tried changing this to link to /usr/bin/clang (a bit ham-fisted, but that seemed to work, and made Cmake compile with clang, though I did have to run cmake again, and it detected that it was using clang.)
However, when I ran
$ scan-build cmake ...
$ scan-build make ...
It didn't do the scan, instead it just compiled as usual. I suspect whatever cmake is doing is thwarting whatever interposing mechanism scan-build uses to make the build scan rather than compile.
FWIW, I was able to get scan-build to run on the Mac under homebrew and got "no bugs found". But that was for the regular build, I haven't got SDL2 set up yet.
Depending on which Linux distribution you're using (and possibly which version thereof), there's a command for updating the alternatives system. For something like cc, it probably updates several links at once, so maybe the ones cmake
is using haven't been updated?
Got SDL2 on my mac, ran scan-build
, here's a report. Now if there's some way to attach a file here...
Thanks!
I fixed a bunch of the things it found. I'm a little surprised it found so little, and such trivial things.