How to compile a module as a shared library in Windows?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Nick74044

Hello,

I have gone through the summator example in the Development tutorials here: Custom modules in C++ — Godot Engine (3.0) documentation in English. I can compile and use the summator module, however I want to set it up so that the module is created as a shared library, so I don’t need to compile the whole engine each time I make changes.

The tutorial for setting this up assumes you are using the GNU compiler, with the command line argument -fPIC. Since I am trying to compile for Windows, the Visual Studio C++ compiler, cl, is used instead, which doesn’t have -fPIC.

I was wondering if anybody knew what changes should be made to the SCsub file so that summator can be made as a shared module using the Visual Studio C++ compiler?

Many Thanks

If at all possible save yourself some headache and use a statically linked lib instead. I remember trying to get dynamic modules to work on windows and at some point I gave up. I don’t remember the showstopper, but if you need to get results fast, a static lib is simply easier. The time to compile godot is really low after the initial build.

omggomb | 2019-01-28 20:22

Okay, sounds like a good idea. I haven’t created static libraries before though. Do you know this would be done for a Godot module? Would it just involve changing the SCsub file and ensuring that the program can find the library?

Thanks for the help

Nick74044 | 2019-01-28 21:01

Just follow the Summator tutorial up until “Improving the build system for development”. Up until there the module is linked statically. After that just build godot using e.g. scons p=windows target=release_debug -j8. Note the -j8 which makes scons use up to 8 threads. If you leave that out it will only use one thread and building will take forever :).

omggomb | 2019-01-29 20:51