Adding libraries to an executable

Rikki Cattermole alphaglosined at gmail.com
Sat Sep 7 03:13:37 PDT 2013


On Saturday, 7 September 2013 at 09:05:39 UTC, Rikki Cattermole 
wrote:
> On Friday, 6 September 2013 at 21:31:59 UTC, Anton Alexeev 
> wrote:
>> I've written a program which uses curl library. So on a PC 
>> without curl the program will not work until you install the 
>> library. Is there a way to put the curl library in the 
>> executable?
>
> You just gave me an idea to compile in shared libraries and 
> then to extract them on run.
> I'll let you know when I got some code.
> (Btw this is not a good idea but definitely will work for 
> license reasons, although this could be a rather gray zone. 
> Should be confirmed.).

So I modified my Bin2D which allows compiling in resources[1].
Now it can produce an output file that when compiled in gives two 
new functions.
These functions essentially extract the files for you.
One of those is for temporary directory[2].

Little bit off topic but it can be utilised for packaging up 
shared libraries into your executable and then extracting on run.

E.g.
$ dub build
$ cd bin
$ ./Bin2D outputFile.d=outputModule lib1.so lib2.dll
Just an example usage. Note not on dub repository.

Just another option for ya.

[1] https://github.com/rikkimax/Bin2D/blob/master/source/Bin2D.d
[2] string[string] outputBin2D2FS()


More information about the Digitalmars-d-learn mailing list