www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Shared library module system with dub

reply Pillager86 <ismail.ax.2011 gmail.com> writes:
What is the correct multi-platform way to build one dub project 
as a shared library, and load said shared library in a separate 
dub project? So far I am able to load a shared library and run a 
function from it (had to extern(C) it to get the symbol to load) 
by using "targetType":"dynamicLibrary" in the shared library 
project, but the main program exits with code -11 and if I don't 
unload the library manually I get a weird "Aborting from 
src/rt/sections_elf_shared.d(500) DSO being unregistered isn't 
current last one.Program exited with code -6" error that Google 
knows nothing about.

I'm trying to add a module system to DMildew because the core 
runtime is over 50 MB in the debug build. Libraries would be 
written in regular D and optionally dynamically loaded by a 
regular D application that links to the core static library (the 
DMildew runtime).
Mar 01 2021
next sibling parent reply Pillager86 <ismail.ax.2011 gmail.com> writes:
Update: the dub "dynamicLibrary" target option is busted on 
Windows and does not build anything at all. This should be filed 
as a bug.
Mar 01 2021
parent reply Pillager86 <ismail.ax.2011 gmail.com> writes:
On Tuesday, 2 March 2021 at 03:42:14 UTC, Pillager86 wrote:
 Update: the dub "dynamicLibrary" target option is busted on 
 Windows and does not build anything at all. This should be 
 filed as a bug.
Update again: I got the Windows DLL to build and run without crashing, but I don't know how to put specific platform options in dub. I need "dflags" "-defaultlibrary=phobos2" or something on Linux but not Windows.
Mar 01 2021
parent reply Pillager86 <ismail.ax.2011 gmail.com> writes:
On Tuesday, 2 March 2021 at 04:13:31 UTC, Pillager86 wrote:
 On Tuesday, 2 March 2021 at 03:42:14 UTC, Pillager86 wrote:
 Update: the dub "dynamicLibrary" target option is busted on 
 Windows and does not build anything at all. This should be 
 filed as a bug.
Update again: I got the Windows DLL to build and run without crashing, but I don't know how to put specific platform options in dub. I need "dflags" "-defaultlibrary=phobos2" or something on Linux but not Windows.
Also, what do you do if the shared library needs to refer to types in the main static library?
Mar 01 2021
parent evilrat <evilrat666 gmail.com> writes:
On Tuesday, 2 March 2021 at 04:26:52 UTC, Pillager86 wrote:
 On Tuesday, 2 March 2021 at 04:13:31 UTC, Pillager86 wrote:
 On Tuesday, 2 March 2021 at 03:42:14 UTC, Pillager86 wrote:
 Update: the dub "dynamicLibrary" target option is busted on 
 Windows and does not build anything at all. This should be 
 filed as a bug.
Update again: I got the Windows DLL to build and run without crashing, but I don't know how to put specific platform options in dub. I need "dflags" "-defaultlibrary=phobos2" or something on Linux but not Windows.
Try this (for dub.json) "dflags-linux": ["-defaultlibrary=phobos2"] For platform/architecture/compiler specific variants just add suffix like this, also works with lflags, and I guess pretty much any other options. "dflags-linux" : ["specific flags for linux"] "dflags-windows" : ["specific flags for windows"] "dflags-windows-dmd" : ["more flags if building with dmd"] "dflags-windows-dmd-x86" : ["even more flags if building for x86 using dmd"]
 Also, what do you do if the shared library needs to refer to 
 types in the main static library?
You need to link it with your DLL, this will however will create lots of duplicated symbols in your executable. In most cases this is undesireable, so instead one will usually put all common stuff into DLL and share across main executable and other DLL's that relies on it. On Windows however DLL support is unfinished, so you are stuck with hacks and/or static libs option.
Mar 01 2021
prev sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Tuesday, 2 March 2021 at 00:40:06 UTC, Pillager86 wrote:
 What is the correct multi-platform way to build one dub project 
 as a shared library, and load said shared library in a separate 
 dub project? So far I am able to load a shared library and run 
 a function from it (had to extern(C) it to get the symbol to 
 load) by using "targetType":"dynamicLibrary" in the shared 
 library project, but the main program exits with code -11 and 
 if I don't unload the library manually I get a weird "Aborting 
 from src/rt/sections_elf_shared.d(500) DSO being unregistered 
 isn't current last one.Program exited with code -6" error that 
 Google knows nothing about.

 [...]
https://www.flipcause.com/secure/cause_pdetails/ODcyMDE=
Mar 02 2021
parent Pillager86 <ismail.ax.2011 gmail.com> writes:
On Tuesday, 2 March 2021 at 10:00:46 UTC, Imperatorn wrote:
 On Tuesday, 2 March 2021 at 00:40:06 UTC, Pillager86 wrote:
 What is the correct multi-platform way to build one dub 
 project as a shared library, and load said shared library in a 
 separate dub project? So far I am able to load a shared 
 library and run a function from it (had to extern(C) it to get 
 the symbol to load) by using "targetType":"dynamicLibrary" in 
 the shared library project, but the main program exits with 
 code -11 and if I don't unload the library manually I get a 
 weird "Aborting from src/rt/sections_elf_shared.d(500) DSO 
 being unregistered isn't current last one.Program exited with 
 code -6" error that Google knows nothing about.

 [...]
https://www.flipcause.com/secure/cause_pdetails/ODcyMDE=
I see the problem now. On Linux I can load a ScriptFunction into the Interpreter instance and run it. On Windows, it crashes with invalid memory access. How sad. DMildew modules will be a POSIX-only feature and that's OK because more people need to adopt other OS besides Windows, which was created by a psychopath anyway.
Mar 02 2021