This is the content of the SConstruct file:
#!python
import os
cppfiletodll = 'theone.cpp'
env = DefaultEnvironment()
env = Environment(tools = ['mingw'])
env['CXX'] = 'x86_64-w64-mingw32-g++'
Default(env.SharedLibrary('foo',cppfiletodll))
When run with $ scons it outputs:
x86_64-w64-mingw32-g++ -o theone.o -c theone.cpp
x86_64-w64-mingw32-g++ -shared -o libfoo.so theone.o -Wl,--out-implib,libfoo.a
And the files I get are:
theone.o
libfoo.a
libfoo.so
I need a .dll for Windows, so I adjust the code like below and instead of an .so library, it outputs a .dll. This .dll works on the Windows 10 machine, awesome!
x86_64-w64-mingw32-g++ -o theone.o -c theone.cpp
x86_64-w64-mingw32-g++ -shared -o libfoo.dll theone.o -Wl,--out-implib,libfoo.a
TL;DR
So until here, everything works. But I want this automated. So I go back to the SConstruct file and add .dll suffix like I did for the console command.
#!python
import os
cppfiletodll = 'theone.cpp'
env = DefaultEnvironment()
env = Environment(tools = ['mingw'])
env['CXX'] = 'x86_64-w64-mingw32-g++'
Default(env.SharedLibrary('foo.dll',cppfiletodll))
But this SConstruct file throws an error:
scons: *** A shared library should have exactly one target with the suffix: .so Target(s) are:libfoo.dll
File "/cppCompileTest/SConstruct", line 10, in <module>
Environment: I am working on a GDNative C++ project with Godot Engine. My development machine is Linux, Ubuntu 20.04.3 LTS. I can use this .dll library in Godot Engine and successfully compile the application for Windows 10. This application works on Windows 10. I already have an SConstruct file with prefixes, flags and import libraries for Linux. I want to add .dll compiling in this SConstruct file so that I can export libraries for Linux and Windows with just one click. Command line allows me to compile a .dll with mingw but SConstruct does not.