Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 29, 2020 How do I statically build a project using DUB? | ||||
---|---|---|---|---|
| ||||
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. |
August 29, 2020 Re: How do I statically build a project using DUB? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kirill | 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
|
August 29, 2020 Re: How do I statically build a project using DUB? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kirill | 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++"],
|
August 29, 2020 Re: How do I statically build a project using DUB? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kirill | 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...
|
August 30, 2020 Re: How do I statically build a project using DUB? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | 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?
|
August 30, 2020 Re: How do I statically build a project using DUB? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kirill | 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 |
Copyright © 1999-2021 by the D Language Foundation