www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I statically build a project using DUB?

reply Kirill <kirill.saidov mail.com> writes:
I need a stand-alone executable that does not require the user to 
install any libraries on their computer. Everything should be 
packed into the executable.

I understand that I need to statically link all of the libraries 
I use in my project, but how do I do this? What do I need to add 
to dub.json file? What compiler flags do I need to use?

Thanks in advance.
Aug 29 2020
next sibling parent reply Andre Pany <andre s-e-a-p.de> writes:
On Saturday, 29 August 2020 at 11:27:28 UTC, Kirill wrote:
 I need a stand-alone executable that does not require the user 
 to install any libraries on their computer. Everything should 
 be packed into the executable.

 I understand that I need to statically link all of the 
 libraries I use in my project, but how do I do this? What do I 
 need to add to dub.json file? What compiler flags do I need to 
 use?

 Thanks in advance.
This highly depends on your actual project: - which 3rd party dependencies do you have - are these dependencies d source code only or wrapping C libraries - is the c source code of your dependencies available and you are able to create a static library of them - does the license of the c dependencies allows static linking Kind regards Andre
Aug 29 2020
parent reply Kirill <kirill.saidov mail.com> writes:
On Saturday, 29 August 2020 at 12:06:38 UTC, Andre Pany wrote:
 On Saturday, 29 August 2020 at 11:27:28 UTC, Kirill wrote:
 I need a stand-alone executable that does not require the user 
 to install any libraries on their computer. Everything should 
 be packed into the executable.

 I understand that I need to statically link all of the 
 libraries I use in my project, but how do I do this? What do I 
 need to add to dub.json file? What compiler flags do I need to 
 use?

 Thanks in advance.
This highly depends on your actual project: - which 3rd party dependencies do you have - are these dependencies d source code only or wrapping C libraries - is the c source code of your dependencies available and you are able to create a static library of them - does the license of the c dependencies allows static linking Kind regards Andre
I am trying to link the GTK library. I have the GTK Runtime installed on Windows 10 pc. Do I need to build the static GTK library from the source? Then how do I tell DUB to include that library?
Aug 29 2020
parent Mike Parker <aldacron gmail.com> writes:
On Sunday, 30 August 2020 at 02:38:52 UTC, Kirill wrote:

 I am trying to link the GTK library. I have the GTK Runtime 
 installed on Windows 10 pc.
Unless things have changed in the last few years, GTK is not intended to be linked statically on Windows. You'll have to figure out how to compile it yourself as a static library. I recall reading about this a while back. IIRC, there were also some source changes required. Then there's also the matter of licensing. GTK is released under the LGPL, which means if you statically link then your executable is considered a derivative work and must abide by the distribution terms of the LGPL.
 Do I need to build the static GTK library from the source? Then 
 how do I tell DUB to include that library?
DUB has a "libs" directive in the build settings: https://dub.pm/package-format-sdl.html#build-settings https://dub.pm/package-format-json.html#build-settings
Aug 29 2020
prev sibling next sibling parent Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= <aferust gmail.com> writes:
On Saturday, 29 August 2020 at 11:27:28 UTC, Kirill wrote:
 I need a stand-alone executable that does not require the user 
 to install any libraries on their computer. Everything should 
 be packed into the executable.

 I understand that I need to statically link all of the 
 libraries I use in my project, but how do I do this? What do I 
 need to add to dub.json file? What compiler flags do I need to 
 use?

 Thanks in advance.
In dub.json: "libs": ["exlib1", "exlib2"], For any libexlib1.a or exlib2.lib, omit the extensions. You can also do it like: "lflags": ["-lstdc++"],
Aug 29 2020
prev sibling parent James Blachly <james.blachly gmail.com> writes:
On Saturday, 29 August 2020 at 11:27:28 UTC, Kirill wrote:
 I need a stand-alone executable that does not require the user 
 to install any libraries on their computer. Everything should 
 be packed into the executable.

 I understand that I need to statically link all of the 
 libraries I use in my project, but how do I do this? What do I 
 need to add to dub.json file? What compiler flags do I need to 
 use?

 Thanks in advance.
It may be extremely difficult if you intend to also link libc; the gethostbyname DNS functions in glibc do not support static linking. OTOH you can create a fairly portably binary by static linking everything EXCEPT libc (I.e., do not pass -static flag to linker) — here you would need to link to the .a files of all your projects library deps as well as your dependencies dependencies...
Aug 29 2020