Subject: Re: why does i686-w64-mingw32-gcc -static fail?
From: Brian Inglis <[email-masked]>
To: [email-masked]
Date: Thu, 17 Dec 2020 22:29:32 -0700
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>

On 2020-12-17 20:45, Lee via Cygwin wrote:
> Would someone please explain why adding "-static" makes
> i686-w64-mingw32-gcc fail?
> 
> This works (or at least the compiler doesn't complain)
> 
> $ i686-w64-mingw32-gcc -o a.exe         conftest-pcre.c -lpcreposix -lpcre
> 
> This does not work
> 
> $ i686-w64-mingw32-gcc -o a.exe -static conftest-pcre.c -lpcreposix -lpcre
> /usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld:
> cannot find -lpcreposix
> /usr/lib/gcc/i686-w64-mingw32/10/../../../../i686-w64-mingw32/bin/ld:
> cannot find -lpcre
> collect2: error: ld returned 1 exit status
> 
> Why does adding "-static" make it fail?

Because the mingw64-*86*-pcre/2 packages provide only dynamic libraries and 
their linkage archives:

usr/i686-w64-mingw32/sys-root/mingw/bin/libpcre-1.dll
usr/i686-w64-mingw32/sys-root/mingw/bin/libpcre16-0.dll
usr/i686-w64-mingw32/sys-root/mingw/bin/libpcre32-0.dll
usr/i686-w64-mingw32/sys-root/mingw/bin/libpcrecpp-0.dll
usr/i686-w64-mingw32/sys-root/mingw/bin/libpcreposix-0.dll
usr/i686-w64-mingw32/sys-root/mingw/lib/libpcre.dll.a
usr/i686-w64-mingw32/sys-root/mingw/lib/libpcre16.dll.a
usr/i686-w64-mingw32/sys-root/mingw/lib/libpcre32.dll.a
usr/i686-w64-mingw32/sys-root/mingw/lib/libpcrecpp.dll.a
usr/i686-w64-mingw32/sys-root/mingw/lib/libpcreposix.dll.a

where others provide both dynamic and static libraries e.g. mingw64-i686-zstd:

usr/i686-w64-mingw32/sys-root/mingw/bin/libzstd-1.dll
usr/i686-w64-mingw32/sys-root/mingw/lib/libzstd.a
usr/i686-w64-mingw32/sys-root/mingw/lib/libzstd.dll.a

possibly where the size of useful library members are reasonably small enough, 
and unlikely to need significantly updated, to be statically linked into an 
standalone executable or embedded system component, that itself may be regularly 
updated, rather than requiring large chunks of a framework to be linked that may 
need regular updates.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]
--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple