I recently installed mingw-w64 and am trying to build programs using SCons. Here's an example of a SConstruct
file I've been trying to use:
env = Environment(tools = ['mingw'])
env.Program('test.c')
However, I get the following error:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: warning: No version of Visual Studio compiler found - C/C++ compilers most likely not set correctly
File "C:\Python27\Scripts\scons.py", line 199, in <module>
gcc -o test.o -c test.c
'gcc' is not recognized as an internal or external command,
operable program or batch file.
scons: *** [test.o] Error 1
scons: building terminated because of errors.
I have set my PATH
variable correctly and can use gcc
through the command line, so it's strange that SCons can't find it. The location of gcc is C:\Program Files\mingw-w64\mingw64\bin
.
Another thing I find strange is having to specify tools. The man page says that mingw is its second preference. I'm guessing this is related to the above issue.
The SCons FAQ (found on the project's website https://www.scons.org) has the answer to this most asked question, Why doesn't SCons find my compiler/linker?
You have to propagate your shell PATH to your build environment. By default, SCons creates clean build environments without any settings in it, such that one can guarantee repeatable builds.
As described in the FAQ, add the following to your SConstruct:
import os
env = Environment(tools = ['mingw'], ENV = {'PATH' : os.environ['PATH']})