I'm trying to make scan-build
use clang instead of gcc for compiling, but for some reason scons
always uses gcc.
If I execute scons
, I get this:
scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... /usr/bin/clang++ -o src/game.o -c -std=c++1z -pedantic -Wall -Wextra -Werror -O3 src/game.cpp src/game.cpp:13:62: error: unknown type name 'a' constexpr std::array<piece_t, game::pieces_num> game::pieces;a ^ src/game.cpp:15:7: error: constructor cannot have a return type game::game() noexcept { ^~~~ src/game.cpp:16:5: error: use of undeclared identifier 'regen_pieces' regen_pieces(); ^ 3 errors generated. scons: *** [src/game.o] Error 1 scons: building terminated because of errors.
As you can see, it correctly uses clang++
instead of g++
. I achieved this using the answer in this question.
But, if I execute scan-build scons
, I get this:
scan-build: Using '/usr/bin/clang-4.0' for static analysis scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... /usr/bin/../lib/clang/c++-analyzer -o src/game.o -c -std=c++1z -pedantic -Wall -Wextra -Werror -O3 src/game.cpp src/game.cpp:13:62: error: 'a' does not name a type constexpr std::array<piece_t, game::pieces_num> game::pieces;a ^ scons: *** [src/game.o] Error 1 scons: building terminated because of errors. scan-build: Removing directory '/tmp/scan-build-2017-04-27-213151-27247-1' because it contains no reports. scan-build: No bugs found.
Because the error messages are different, scan-build
used gcc instead of clang.
Here is my output for my environment variables:
$ printenv | grep clang
CC=/usr/bin/clang
CXX=/usr/bin/clang++
And my SConstruct
file:
import os
env = Environment()
env["CC"] = os.getenv("CC") or env["CC"]
env["CXX"] = os.getenv("CXX") or env["CXX"]
env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
env["ENV"]["TERM"] = os.environ["TERM"]
env.Append(CXXFLAGS = "-std=c++1z -pedantic -Wall -Wextra -Werror -O3")
env.Append(LIBS = ["pthread"])
env.Program("game", ["src/game.cpp", "src/main.cpp"])
So, my question is how can I make scan-build
use clang?
If you don't specify a compiler, scan-build
will not read the environment variables, but will instead guess. In your case, it guessed that the suitable compiler was gcc.
scan-build
's developers are trying to fix this, but in the mean time, you have to explicitly specify the compiler when building:
$ scan-build --use-c++=clang++ scons