public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Link error with static version of zlib?
@ 2017-07-19 15:47 J
  2017-07-20 14:07 ` Steven Penny
  0 siblings, 1 reply; 7+ messages in thread
From: J @ 2017-07-19 15:47 UTC (permalink / raw)
  To: cygwin

Hello,

I am trying to produce an executable using mingw that uses all-static
linking, that is, that it does not rely on any DLLs except possibly
the Microsoft msvcrt.dll

Is it possible?

If I am not mistaken, when selecting the package mingw64-x86_64-zlib
with the installer, it installs the library, which has been compiled
as both a DLL and a static library.

But it appears that the minizip library included within the zlib
package is only present in DLL form.

When building, I get the following

make
x86_64-w64-mingw32-g++ -O2 -fno-strength-reduce -O2
-fno-strength-reduce -g
-I/usr/x86_64-w64-mingw32/sys-root/mingw/include/     -DDEBUG -D_WIN32
 -std=c++11   -c -o main.o main.cpp
x86_64-w64-mingw32-g++ -o app.exe -O2 -fno-strength-reduce -g -Wall
-Wpointer-arith -L/usr/lib main.o -mwindows -static -lws2_32 -lgdi32
-lcomctl32 -lcomdlg32 -lminizip -lz
-Wl,--enable-auto-import,--enable-runtime-pseudo-reloc
/usr/lib/gcc/x86_64-w64-mingw32/5.4.0/../../../../x86_64-w64-mingw32/bin/ld:
cannot find -lminizip
collect2: error: ld returned 1 exit status


But yet, when I build the with the exact same command on linux, I get
an executable and it depends only on msvcrt.dll (and comctl32.dll,
comdlg32.dll, kernel32.dll, user32.dll and ws2_32.dll, obviously).

If I modify the link line to instead link -lminizip.dll, I get the
following errors

/usr/lib/libpthread.a(t-d001060.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_getspecific'
/usr/lib/libpthread.a(t-d001062.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_key_create'
/usr/lib/libpthread.a(t-d001063.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_key_delete'
/usr/lib/libpthread.a(t-d001065.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_destroy'
/usr/lib/libpthread.a(t-d001067.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_init'
/usr/lib/libpthread.a(t-d001068.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_lock'
/usr/lib/libpthread.a(t-d001071.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_unlock'
/usr/lib/libpthread.a(t-d001101.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_setspecific'
collect2: error: ld returned 1 exit status

Is there a proper way of getting the minizip lib statically-compiled?

Thank you

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Link error with static version of zlib?
  2017-07-19 15:47 Link error with static version of zlib? J
@ 2017-07-20 14:07 ` Steven Penny
  2017-07-20 14:16   ` J
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Penny @ 2017-07-20 14:07 UTC (permalink / raw)
  To: cygwin

On Wed, 19 Jul 2017 11:07:42, J wrote:
> If I am not mistaken, when selecting the package mingw64-x86_64-zlib
> with the installer, it installs the library, which has been compiled
> as both a DLL and a static library.
> 
> But it appears that the minizip library included within the zlib
> package is only present in DLL form.

1. mingw64-x86_64-zlib package does not include minizip

        $ sage listfiles mingw64-x86_64-zlib
        usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.a
        usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.dll.a

2. mingw64-x86_64-zlib doesnt even pull in the minizip package:

        $ sage-cost.sh mingw64-x86_64-zlib
           73,920 desktop-file-utils
           52,608 gamin
          478,080 gsettings-desktop-schemas
           11,592 libfam0
        2,885,964 libglib2.0_0
          693,532 libxml2
           56,616 mingw64-x86_64-pkg-config
          109,828 mingw64-x86_64-zlib
           56,536 pkg-config
          299,232 shared-mime-info

3. The package you are looking for is mingw64-x86_64-minizip, which doesnt get
   pulled in from anything:

        $ sage rdepends mingw64-x86_64-minizip
        mingw64-x86_64-minizip

   you have to manually install it.

4. You are rigth about the DLL:

       $ sage listfiles mingw64-x86_64-minizip
       usr/x86_64-w64-mingw32/sys-root/mingw/bin/libminizip-1.dll
       usr/x86_64-w64-mingw32/sys-root/mingw/lib/libminizip.dll.a

If you want the static version, you need to build it yourself, or post issue
here:

http://github.com/cygwinports/mingw64-x86_64-zlib

Good luck on this though:

- http://github.com/cygwinports/mingw64-x86_64-lua/issues/1
- http://github.com/cygwinports/mingw64-x86_64-nghttp2/issues/1
- http://github.com/cygwinports/mingw64-x86_64-pcre/issues/1
- http://github.com/cygwinports/mingw64-x86_64-expat/issues/1

Alternatively you can get it from here:

http://repo.msys2.org/mingw/x86_64


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Link error with static version of zlib?
  2017-07-20 14:07 ` Steven Penny
@ 2017-07-20 14:16   ` J
  2017-07-21  0:32     ` Hans-Bernhard Bröker
  0 siblings, 1 reply; 7+ messages in thread
From: J @ 2017-07-20 14:16 UTC (permalink / raw)
  To: cygwin

Hello Steven,

    Thank you very much for taking the time to reply to my question!

I downloaded
http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-zlib-1.2.8-9-any.pkg.tar.xz

I then copied the file libminizip.a contained within to
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/
I also copied the file libz.a contained within to
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/
making sure to rename the original file to libz.a.old so I can undo,
if necessary.

The rationale for doing this is that those two files are the only two
dependencies outside of the Windows system dlls the project uses.

However, at the link, there was still an error:

/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libminizip.a(unzip.o):(.text+0x13b9):
undefined reference to `BZ2_bzDecompress'
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libminizip.a(unzip.o):(.text+0x1605):
undefined reference to `BZ2_bzDecompressEnd'
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libminizip.a(unzip.o):(.text+0x1d65):
undefined reference to `BZ2_bzDecompressInit'
/usr/lib/libpthread.a(t-d001060.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_getspecific'
/usr/lib/libpthread.a(t-d001062.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_key_create'
/usr/lib/libpthread.a(t-d001063.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_key_delete'
/usr/lib/libpthread.a(t-d001065.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_destroy'
/usr/lib/libpthread.a(t-d001067.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_init'
/usr/lib/libpthread.a(t-d001068.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_lock'
/usr/lib/libpthread.a(t-d001071.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_mutex_unlock'
/usr/lib/libpthread.a(t-d001101.o):fake:(.text+0x2): undefined
reference to `__imp_pthread_setspecific'


I've tried linking the thread library, but it does not seem to make a
difference.

I'm not sure how to proceed.

On Wed, Jul 19, 2017 at 9:41 PM, Steven Penny <svnpenn@gmail.com> wrote:
> On Wed, 19 Jul 2017 11:07:42, J wrote:
>>
>> If I am not mistaken, when selecting the package mingw64-x86_64-zlib
>> with the installer, it installs the library, which has been compiled
>> as both a DLL and a static library.
>>
>> But it appears that the minizip library included within the zlib
>> package is only present in DLL form.
>
>
> 1. mingw64-x86_64-zlib package does not include minizip
>
>        $ sage listfiles mingw64-x86_64-zlib
>        usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.a
>        usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.dll.a
>
> 2. mingw64-x86_64-zlib doesnt even pull in the minizip package:
>
>        $ sage-cost.sh mingw64-x86_64-zlib
>           73,920 desktop-file-utils
>           52,608 gamin
>          478,080 gsettings-desktop-schemas
>           11,592 libfam0
>        2,885,964 libglib2.0_0
>          693,532 libxml2
>           56,616 mingw64-x86_64-pkg-config
>          109,828 mingw64-x86_64-zlib
>           56,536 pkg-config
>          299,232 shared-mime-info
>
> 3. The package you are looking for is mingw64-x86_64-minizip, which doesnt
> get
>   pulled in from anything:
>
>        $ sage rdepends mingw64-x86_64-minizip
>        mingw64-x86_64-minizip
>
>   you have to manually install it.
>
> 4. You are rigth about the DLL:
>
>       $ sage listfiles mingw64-x86_64-minizip
>       usr/x86_64-w64-mingw32/sys-root/mingw/bin/libminizip-1.dll
>       usr/x86_64-w64-mingw32/sys-root/mingw/lib/libminizip.dll.a
>
> If you want the static version, you need to build it yourself, or post issue
> here:
>
> http://github.com/cygwinports/mingw64-x86_64-zlib
>
> Good luck on this though:
>
> - http://github.com/cygwinports/mingw64-x86_64-lua/issues/1
> - http://github.com/cygwinports/mingw64-x86_64-nghttp2/issues/1
> - http://github.com/cygwinports/mingw64-x86_64-pcre/issues/1
> - http://github.com/cygwinports/mingw64-x86_64-expat/issues/1
>
> Alternatively you can get it from here:
>
> http://repo.msys2.org/mingw/x86_64
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Link error with static version of zlib?
  2017-07-20 14:16   ` J
@ 2017-07-21  0:32     ` Hans-Bernhard Bröker
  2017-07-21 10:11       ` Steven Penny
  0 siblings, 1 reply; 7+ messages in thread
From: Hans-Bernhard Bröker @ 2017-07-21  0:32 UTC (permalink / raw)
  To: cygwin

Am 20.07.2017 um 16:07 schrieb J:
> Hello Steven,
> 
>      Thank you very much for taking the time to reply to my question!
> 
> I downloaded
> http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-zlib-1.2.8-9-any.pkg.tar.xz

And that's where you went off in the wrong direction.  You're writing to 
the Cygwin mailing, but that's the MSYS2 package repository.  Those are 
two different environments, so you should _not_ mix up them up like that.

> The rationale for doing this is that those two files are the only two
> dependencies outside of the Windows system dlls the project uses.

That's a valid reason to get yourself a local version of minizip, but 
_not_ a reason to just plunk MSYS2 files into the middle of a cygwin 
installation.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Link error with static version of zlib?
  2017-07-21  0:32     ` Hans-Bernhard Bröker
@ 2017-07-21 10:11       ` Steven Penny
  2017-07-24 23:55         ` J (Jean-Claude Gervais)
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Penny @ 2017-07-21 10:11 UTC (permalink / raw)
  To: cygwin

On Thu, 20 Jul 2017 20:59:00, =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?= wrote:
> And that's where you went off in the wrong direction.  You're writing to 
> the Cygwin mailing, but that's the MSYS2 package repository.  Those are 
> two different environments, so you should _not_ mix up them up like that.

This is a pretty awful response. The MSYS2 part of my answer, the part OP tried
is certainly possible. When Cygwin package maintainers are ignoring serious
package issues for months:

- http://cygwin.com/ml/cygwin/2017-07/msg00055.html
- http://github.com/cygwinports/mingw64-x86_64-expat/issues/1
- http://github.com/cygwinports/mingw64-x86_64-lua/issues/1
- http://github.com/cygwinports/mingw64-x86_64-nghttp2/issues/1
- http://github.com/cygwinports/mingw64-x86_64-pcre/issues/1

it is not wrong to seek a sane alternative, which this is. You certainly can mix
these as in this case we are not involving the Cygwin DLL. To J (OP), if you
want a real answer and not this brush off, repost your question here and I will
try to work with you:

http://github.com/svnpenn/glade

as technically your original question has already been answered (by me), and
your new issue is outside the scope of this mailing list.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Link error with static version of zlib?
  2017-07-21 10:11       ` Steven Penny
@ 2017-07-24 23:55         ` J (Jean-Claude Gervais)
  2017-07-25 14:42           ` cyg Simple
  0 siblings, 1 reply; 7+ messages in thread
From: J (Jean-Claude Gervais) @ 2017-07-24 23:55 UTC (permalink / raw)
  To: cygwin

Hello Steven and Hans-Bernhard,

I believe the problem stems from a missing component in the runtime.

When I use Gentoo's Crossdev and generate either the 32 or 64 bit
version of MinGW, it allows me to compile and link the app with no
other dependencies than msvcrt.dll. I can run the cross-compiled app
directly on Windows.

But for some reason, the MinGW compiler present in Cygwin looks for
threading support which is not there.

This is strange because I manually compiled the source for both
libraries (zlib with minizip in the contrib folder) and it gives the
same error.

Searching the source for any mention of threads in the code yields
nothing except comments about whether routines are thread-safe or not.

The link complains about those functions missing from libpthread.a,
even though that library is not invoked.

I've tried linking the pthread library, but it does not supply the
missing symbols.

So those symbols have to either be present in a lib that is missing
from the link-line, which would be strange because the same link-line
works with the linux version of MinGW

or

the runtime library needs to supply them?

I'll try and narrow it down more.

Thank you both for your help.

J



On Thu, 2017-07-20 at 18:01 -0700, Steven Penny wrote:
> On Thu, 20 Jul 2017 20:59:00, =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?=
> wrote:
> > And that's where you went off in the wrong direction.  You're
> > writing to 
> > the Cygwin mailing, but that's the MSYS2 package repository.  Those
> > are 
> > two different environments, so you should _not_ mix up them up like
> > that.
> 
> This is a pretty awful response. The MSYS2 part of my answer, the
> part OP tried
> is certainly possible. When Cygwin package maintainers are ignoring
> serious
> package issues for months:
> 
> - http://cygwin.com/ml/cygwin/2017-07/msg00055.html
> - http://github.com/cygwinports/mingw64-x86_64-expat/issues/1
> - http://github.com/cygwinports/mingw64-x86_64-lua/issues/1
> - http://github.com/cygwinports/mingw64-x86_64-nghttp2/issues/1
> - http://github.com/cygwinports/mingw64-x86_64-pcre/issues/1
> 
> it is not wrong to seek a sane alternative, which this is. You
> certainly can mix
> these as in this case we are not involving the Cygwin DLL. To J (OP),
> if you
> want a real answer and not this brush off, repost your question here
> and I will
> try to work with you:
> 
> http://github.com/svnpenn/glade
> 
> as technically your original question has already been answered (by
> me), and
> your new issue is outside the scope of this mailing list.
> 
> 
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> 

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

* Re: Link error with static version of zlib?
  2017-07-24 23:55         ` J (Jean-Claude Gervais)
@ 2017-07-25 14:42           ` cyg Simple
  0 siblings, 0 replies; 7+ messages in thread
From: cyg Simple @ 2017-07-25 14:42 UTC (permalink / raw)
  To: cygwin

On 7/24/2017 7:31 PM, J (Jean-Claude Gervais) wrote:
> Hello Steven and Hans-Bernhard,
> 
> I believe the problem stems from a missing component in the runtime.
> 
> When I use Gentoo's Crossdev and generate either the 32 or 64 bit
> version of MinGW, it allows me to compile and link the app with no
> other dependencies than msvcrt.dll. I can run the cross-compiled app
> directly on Windows.
> 
> But for some reason, the MinGW compiler present in Cygwin looks for
> threading support which is not there.
> 
> This is strange because I manually compiled the source for both
> libraries (zlib with minizip in the contrib folder) and it gives the
> same error.
> 
> Searching the source for any mention of threads in the code yields
> nothing except comments about whether routines are thread-safe or not.
> 
> The link complains about those functions missing from libpthread.a,
> even though that library is not invoked.
> 
> I've tried linking the pthread library, but it does not supply the
> missing symbols.
> 
> So those symbols have to either be present in a lib that is missing
> from the link-line, which would be strange because the same link-line
> works with the linux version of MinGW
> 
> or
> 
> the runtime library needs to supply them?
> 
> I'll try and narrow it down more.
> 

You might get more help if you give the commands used to link the
package.  Note you must have the library specifications after the
objects being linked which is my guess as to the issue.

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

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

end of thread, other threads:[~2017-07-25 11:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-19 15:47 Link error with static version of zlib? J
2017-07-20 14:07 ` Steven Penny
2017-07-20 14:16   ` J
2017-07-21  0:32     ` Hans-Bernhard Bröker
2017-07-21 10:11       ` Steven Penny
2017-07-24 23:55         ` J (Jean-Claude Gervais)
2017-07-25 14:42           ` cyg Simple

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).