public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Question on statically linking with cygwin
@ 2023-09-19 15:24 Johannes Thoma
  2023-09-22  5:54 ` Martin Wege
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Thoma @ 2023-09-19 15:24 UTC (permalink / raw)
  To: cygwin

Hi,

As I understood the reason for not being able to statically link
the cygwin1.dll in to a binary and distribute that is because of
licensing issues. Are there any technical issues that would make
it impossible to link with cygwin statically?

The reason I am asking is I am working on a GPL project
(WinDRBD: https://github.com/LINBIT/windrbd) and am currently
delivering the cygwin1.dll along with the binary. It would be
desireable to have the cygwin1.dll statically linked (for example
to avoid version clashes) instead. Is that technically possible?
If necessary I am ready to compile cygwin (at least the needed
files) on my own.

Thanks for any insights on that topic,

  Best regards,

- Johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question on statically linking with cygwin
  2023-09-19 15:24 Question on statically linking with cygwin Johannes Thoma
@ 2023-09-22  5:54 ` Martin Wege
  2023-09-22 11:12   ` Johannes Thoma
  0 siblings, 1 reply; 6+ messages in thread
From: Martin Wege @ 2023-09-22  5:54 UTC (permalink / raw)
  To: cygwin

On Tue, Sep 19, 2023 at 5:24 PM Johannes Thoma via Cygwin
<cygwin@cygwin.com> wrote:
>
> Hi,
>
> As I understood the reason for not being able to statically link
> the cygwin1.dll in to a binary and distribute that is because of
> licensing issues.

Do you have any references for that?

> Are there any technical issues that would make
> it impossible to link with cygwin statically?
>
> The reason I am asking is I am working on a GPL project
> (WinDRBD: https://github.com/LINBIT/windrbd) and am currently
> delivering the cygwin1.dll along with the binary. It would be
> desireable to have the cygwin1.dll statically linked (for example
> to avoid version clashes) instead. Is that technically possible?
> If necessary I am ready to compile cygwin (at least the needed
> files) on my own.

Interesting.
But how (from a developers perspective) do you link cygwin1.dll
statically into a binary?

Thanks,
Martin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question on statically linking with cygwin
  2023-09-22  5:54 ` Martin Wege
@ 2023-09-22 11:12   ` Johannes Thoma
  2023-10-16 15:28     ` Jon Turney
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Thoma @ 2023-09-22 11:12 UTC (permalink / raw)
  To: cygwin

Hi Martin,

Thanks for your answer, comments inline:

Am 22.09.23 um 07:54 schrieb Martin Wege via Cygwin:
> On Tue, Sep 19, 2023 at 5:24 PM Johannes Thoma via Cygwin
> <cygwin@cygwin.com> wrote:
>>
>> Hi,
>>
>> As I understood the reason for not being able to statically link
>> the cygwin1.dll in to a binary and distribute that is because of
>> licensing issues.
> 
> Do you have any references for that?
I read that in the Cygwin FAQ:

https://cygwin.com/faq/faq.html#faq.programming.static-linking

I read through the licensing options and IMHO linking statically
against cygwin (which is GPL) from a program (like WinDRBD) that
is also GPL should be allowed. But I am not a lawyer ...

> 
>> Are there any technical issues that would make
>> it impossible to link with cygwin statically?
>>
>> The reason I am asking is I am working on a GPL project
>> (WinDRBD: https://github.com/LINBIT/windrbd) and am currently
>> delivering the cygwin1.dll along with the binary. It would be
>> desireable to have the cygwin1.dll statically linked (for example
>> to avoid version clashes) instead. Is that technically possible?
>> If necessary I am ready to compile cygwin (at least the needed
>> files) on my own.
> 
> Interesting.
> But how (from a developers perspective) do you link cygwin1.dll
> statically into a binary?
> 
I would build my own cygwin1.lib or cygwin1.a and statically link
against it.

> Thanks,
> Martin
> 
Best regards,

- Johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question on statically linking with cygwin
  2023-09-22 11:12   ` Johannes Thoma
@ 2023-10-16 15:28     ` Jon Turney
  2023-11-02 17:33       ` Johannes Thoma
  0 siblings, 1 reply; 6+ messages in thread
From: Jon Turney @ 2023-10-16 15:28 UTC (permalink / raw)
  To: Johannes Thoma, Martin Wege, The Cygwin Mailing List

On 22/09/2023 12:12, Johannes Thoma via Cygwin wrote:
> Hi Martin,
> 
> Thanks for your answer, comments inline:
> 
> Am 22.09.23 um 07:54 schrieb Martin Wege via Cygwin:
>> On Tue, Sep 19, 2023 at 5:24 PM Johannes Thoma via Cygwin
>> <cygwin@cygwin.com> wrote:
>>>
>>> Hi,
>>>
>>> As I understood the reason for not being able to statically link
>>> the cygwin1.dll in to a binary and distribute that is because of
>>> licensing issues.
>>
>> Do you have any references for that?
> I read that in the Cygwin FAQ:
> 
> https://cygwin.com/faq/faq.html#faq.programming.static-linking
> 
> I read through the licensing options and IMHO linking statically
> against cygwin (which is GPL) from a program (like WinDRBD) that
> is also GPL should be allowed. But I am not a lawyer ...

That FAQ probably needs clarifying.

The two sentences are probably intended to be taken separately.

So, to be clear, there are technical reasons why the cygwin DLL is not 
also made available as a static library.

>>> Are there any technical issues that would make
>>> it impossible to link with cygwin statically?
>>>
>>> The reason I am asking is I am working on a GPL project
>>> (WinDRBD: https://github.com/LINBIT/windrbd) and am currently
>>> delivering the cygwin1.dll along with the binary. It would be
>>> desireable to have the cygwin1.dll statically linked (for example
>>> to avoid version clashes) instead. Is that technically possible?
>>> If necessary I am ready to compile cygwin (at least the needed
>>> files) on my own.
>>
>> Interesting.
>> But how (from a developers perspective) do you link cygwin1.dll
>> statically into a binary?
>>
> I would build my own cygwin1.lib or cygwin1.a and statically link
> against it.

If you do work out how to do this, patches would be welcome...


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question on statically linking with cygwin
  2023-10-16 15:28     ` Jon Turney
@ 2023-11-02 17:33       ` Johannes Thoma
  2023-11-03 15:48         ` Johannes Thoma
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Thoma @ 2023-11-02 17:33 UTC (permalink / raw)
  To: Jon Turney, Martin Wege, The Cygwin Mailing List

Hi Jon, Hi Martin,

Thanks for your answer, comments inline:

Am 16.10.23 um 17:28 schrieb Jon Turney:
> On 22/09/2023 12:12, Johannes Thoma via Cygwin wrote:
>> Hi Martin,
>>
>> Thanks for your answer, comments inline:
>>
>> Am 22.09.23 um 07:54 schrieb Martin Wege via Cygwin:
>>> On Tue, Sep 19, 2023 at 5:24 PM Johannes Thoma via Cygwin
>>> <cygwin@cygwin.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> As I understood the reason for not being able to statically link
>>>> the cygwin1.dll in to a binary and distribute that is because of
>>>> licensing issues.
>>>
>>> Do you have any references for that?
>> I read that in the Cygwin FAQ:
>>
>> https://cygwin.com/faq/faq.html#faq.programming.static-linking
>>
>> I read through the licensing options and IMHO linking statically
>> against cygwin (which is GPL) from a program (like WinDRBD) that
>> is also GPL should be allowed. But I am not a lawyer ...
> 
> That FAQ probably needs clarifying.
> 
> The two sentences are probably intended to be taken separately.
> 
> So, to be clear, there are technical reasons why the cygwin DLL is not also made available as a static library.
> 
>>>> Are there any technical issues that would make
>>>> it impossible to link with cygwin statically?
>>>>
>>>> The reason I am asking is I am working on a GPL project
>>>> (WinDRBD: https://github.com/LINBIT/windrbd) and am currently
>>>> delivering the cygwin1.dll along with the binary. It would be
>>>> desireable to have the cygwin1.dll statically linked (for example
>>>> to avoid version clashes) instead. Is that technically possible?
>>>> If necessary I am ready to compile cygwin (at least the needed
>>>> files) on my own.
>>>
>>> Interesting.
>>> But how (from a developers perspective) do you link cygwin1.dll
>>> statically into a binary?
>>>
>> I would build my own cygwin1.lib or cygwin1.a and statically link
>> against it.
> 
> If you do work out how to do this, patches would be welcome...
> 
You are right it is far from trivial. I am working on it, not
sure now if it will be possible or how long it takes (my main
project is WinDRBD, so unfortunately I cannot spend full time on
getting static linking work). Right now, I can compile cygwin on my own
and digged a little bit in the program startup code (lib subdir),
I will keep you updated once I go along.

Best regards,

- Johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question on statically linking with cygwin
  2023-11-02 17:33       ` Johannes Thoma
@ 2023-11-03 15:48         ` Johannes Thoma
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes Thoma @ 2023-11-03 15:48 UTC (permalink / raw)
  To: cygwin

Hi,

As I promised some updates below.

Am 02.11.23 um 18:33 schrieb Johannes Thoma via Cygwin:
>>>> [...]
>>>> Interesting.
>>>> But how (from a developers perspective) do you link cygwin1.dll
>>>> statically into a binary?
>>>>
>>> I would build my own cygwin1.lib or cygwin1.a and statically link
>>> against it.
>>
>> If you do work out how to do this, patches would be welcome...
>>
> You are right it is far from trivial. I am working on it, not
> sure now if it will be possible or how long it takes (my main
> project is WinDRBD, so unfortunately I cannot spend full time on
> getting static linking work). Right now, I can compile cygwin on my own
> and digged a little bit in the program startup code (lib subdir),
> I will keep you updated once I go along.
> 

I can link a simple hello world program (which uses write(2) to
produce output to test the POSIX variant) with something like:

LDFLAGS=-L. -lcygwin-static -lcygserver -lntdll -lkernel32 -lc -lg -lm -lgcc -static -nodefaultlibs

and copiing the newlib libc, libm and other libraries from the
build. The ntdll and kernel32 libs are from a mingw-w64 installation.

the cygwin-static library contains every .o file in the winsup/cygwin
build directory except: lib/libcmain.o and ctype.o (for now had to
patch __set_ctype out of cygwin and take the newlib version, maybe
I can fix that somehow).

Right now it links and produces a (22 Megabytes) EXE binary, however
it crashes in the thread_allocator C++ class (most likely because the
matching constructor is not called before that) this will be the
next thing to fix.

Ok have a great weekend everybody and I will get back once I continue
on the static linking feature.

Best regards,

- Johannes

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-03 15:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19 15:24 Question on statically linking with cygwin Johannes Thoma
2023-09-22  5:54 ` Martin Wege
2023-09-22 11:12   ` Johannes Thoma
2023-10-16 15:28     ` Jon Turney
2023-11-02 17:33       ` Johannes Thoma
2023-11-03 15:48         ` Johannes Thoma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).