Search code examples
linuxgnusconsmingw-w64win64

In GNU/Linux, how do I use mingw-w64 with SCons to produce a 64-bit Windows executable?


I'm using Linux Mint.

How can I use mingw-w64 with SCons to produce a 64-bit Windows executable? I'm using:

Environment(tools = ['mingw'], ...)

but it seems to use g++ anyway.


Solution

  • I'm using fedora 23, but I see the same behavior there that you describe, and here is a solution... Once you specify the mingw tool, it will setup the environment correctly with extensions and such, but you may have to tell it where your compiler and linker are. I'm sure it's different on every distribution...

    >> scons --version
    SCons by Steven Knight et al.:
        script: v2.3.6.rel_2.3.5:3347:d31d5a4e74b6[MODIFIED], 2015/07/31 14:36:10, by bdbaddog on hpmicrodog
        engine: v2.3.6.rel_2.3.5:3347:d31d5a4e74b6[MODIFIED], 2015/07/31 14:36:10, by bdbaddog on hpmicrodog
        engine path: ['/usr/lib/scons/SCons']
    Copyright (c) 2001 - 2015 The SCons Foundation
    
    >> tree  
    .
    ├── main.cpp
    └── SConstruct
    
    0 directories, 2 files
    
    >> cat main.cpp
    #include <iostream>
    int main() { std::cout << "Hello World" << std::endl; }
    
    >> cat SConstruct 
    env = Environment(tools = ['mingw'])
    env.Replace(CXX='/usr/bin/x86_64-w64-mingw32-g++',
                LINK='/usr/bin/x86_64-w64-mingw32-g++')
    env.Program('main.cpp')
    
    >> scons
    scons: Reading SConscript files ...
    scons: done reading SConscript files.
    scons: Building targets ...
    /usr/bin/x86_64-w64-mingw32-g++ -o main.o -c main.cpp
    /usr/bin/x86_64-w64-mingw32-g++ -o main.exe main.o
    scons: done building targets.
    
    >> tree
    .
    ├── main.cpp
    ├── main.exe
    ├── main.o
    └── SConstruct
    
    0 directories, 4 files
    
    >> file main.exe
    main.exe: PE32+ executable (console) x86-64, for MS Windows