14

I'm trying to build the C++ port of zxing on Windows, but scons fails with:

cl : Command line error D8021 : invalid numeric argument '/Wextra'

I have both VS2010 and MinGW installed, and scons tries to use the MSVC compiler, even though the SConscript file assumes gcc and use gcc-specific parameters, which causes the error.

How can I tell scons to use MinGW instead?

sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

17

Scons uses MSVC compiler by default on windows. To set mignw compiler use tools parameter while creating Environment object.

env = Environment(tools = ['mingw'])

And then use env.Program() instead of Program().

sashoalm
  • 75,001
  • 122
  • 434
  • 781
Torsten
  • 21,726
  • 5
  • 24
  • 31
  • did not work for me. It says cc = gcc but then when building targets it still uses cl (bug?) – ljgww Jan 27 '17 at 14:38
  • 1
    found it: it shall be env.Program(...) instead of Program(your_code) see: http://stackoverflow.com/questions/21242206/scons-cant-pick-the-compiler-mingw – ljgww Feb 20 '17 at 11:02
  • @ljgww Either call `env.Program` like you found out or change the default construction environment instead of creating a new one. You can do it by calling `DefaultEnvironment` instead of `Environment`. – Piotr Siupa May 14 '22 at 09:55
  • As far as I know there may be some complication if yo won't also specify MinGW linker in the `tools`. I think it is called `gnulink`. There is also answer for a different question which shows another way to set tools: https://stackoverflow.com/a/11391819/3052438 – Piotr Siupa May 14 '22 at 09:59
2

Below is my working SConstruct for mingw on Windows:

import os

env = Environment(ENV={'PATH': os.environ['PATH'], 'TEMP': os.environ['TEMP']}, tools=['mingw'])
env.Program('main.cpp')

Windows Environment variables PATH and TEMP can be set externally. Environment variable PATH should include the bin folder path of mingw.

bhadra
  • 12,887
  • 10
  • 54
  • 47