How package Dlang in a standalone portable executable?

WebFreak001 d.forum at webfreak.org
Fri Mar 27 07:23:40 UTC 2020


On Thursday, 26 March 2020 at 23:19:20 UTC, Marcone wrote:
> I need package Dlang in a standalone portable executable.
> I need packcages all dependencies, dlls, files, etc in one 
> executable file.

by default if you use dub it will statically link phobos and 
druntime into the executable, so you have no external 
dependencies other than libc / msvc++ runtime redist. This might 
not be the case depending on your installation though like for 
example in LDC the config might default to using a shared ldc 
phobos runtime as this is the case for example on ArchLinux.

If you use any shared libraries (derelict/bindbc) you will want 
to switch them to statically link. Otherwise libraries on dub are 
statically linked by default.

If you want to compile in your files into the executable, you can 
use `import("filename.txt")` in your code instead of reading from 
a file. The compiler will read the file and embed the contents in 
your code at that point. This is very different from e.g. C# 
where it appends the resources to the executable and inside has 
code to read from it at runtime. If you want to be able to change 
it after compiling, on linux you would probably want to use 
something like AppImages or flatpaks and on OSX I think they have 
application bundles for this.

The system dependencies (libc / msvc++ runtime and win32 api) you 
will still want the user to install them. This ensures 
compatibility with the OS, especially on Windows. For the msvc++ 
runtime you probably want to include their installer in your 
installer. You will have to read up on how that works though.

But with D you can basically just take your executable file and 
distribute it in a lot of default cases. Best to try it out on 
PCs which have freshly installed operating systems though.


More information about the Digitalmars-d-learn mailing list