Windows dependency on libwinpthread-1.dll

1,450 views
Skip to first unread message

aditya siram

unread,
Jan 19, 2017, 11:37:18 AM1/19/17
to fltk.general
Hi,
I'm trying to create self-contained FLTK executables on Windows 10. I'm using MSYS2 to compile and link the test applications but when I compile with the standard './configure' command, I'm seeing a dependence on 'libwinpthread-1.dll':
ldd <executable>
   ...
   libwinpthread-1.dll => ...

I thought this might be happening because 'threads' were enabled so I did './configure --disable-threads' but without success.

Can anyone suggest a way of getting rid of or statically linking in this library?

-deech

Albrecht Schlosser

unread,
Jan 19, 2017, 5:58:22 PM1/19/17
to fltkg...@googlegroups.com
Please read Ian's good advice for building with MSYS and (optionally)
with a 64-bit toolchain. This is the way those of the FLTK team that
build 32-bit and/or 64-bit applications on Windows do it successfully.

That said, I remember that I had the choice to select several options
when downloading and installing the MinGW-W64 (64-bit) gcc compiler
suite. When I selected 'pthread' (or 'posox'?) as opposed to 'win32'
threading all executables depended on libwinpthread-1.dll, no matter how
FLTK was configured. The choice was to download a different MinGW-W64
toolchain. I don't know how you can do this with MSYS2.

To find out which one you have type

$ gcc --version
gcc.exe (x86_64-win32-seh, Built by MinGW-W64 project) 6.1.0

................^^^^^-^^^

The important parts are 'win32' (threads) and 'seh' (exception
handling). If you see something like 'pthread' or 'posix' instead of
'win32' then that's likely the culprit.

What is your output from 'gcc --version'?

As Ian said, we prefer and recommend using MinGW with MSYS (not MSYS2)
and the MinGW-W64 project's toolchain as a separate installation to
build 64-bit executables if you really need it.

One more note: if you want to build native (self-contained,
distributable) Windows executables then you must also
configure/compile/link with

LDFLAGS="-static-libgcc -static-libstdc++'

but that's the next step after you got the right toolchain running.

Albrecht Schlosser

unread,
Jan 19, 2017, 6:00:58 PM1/19/17
to fltkg...@googlegroups.com
On 19.01.2017 23:58 Albrecht Schlosser wrote:

> when downloading and installing the MinGW-W64 (64-bit) gcc compiler
> suite. When I selected 'pthread' (or 'posox'?) as opposed to 'win32'

Correction: should read 'posix', of course, not 'posox'.

Nicholas Shea

unread,
Jan 20, 2017, 4:27:18 AM1/20/17
to fltk.general
If you use the TDM-GCC Compiler Suite for Windows, you will not need to link to any dll at all; TDM-GCC uses a statically-linked libstdc++ by default and winpthreads is also static library. Be sure to read the file "COPYING.winpthreads.txt" in the TDM-GCC distribution. Here is the pertinent extract for your perusal:

<START QUOTE>
*** POSIX threads, C++11 std::thread and other synchronization features ***

As of the 4.8.1 TDM-GCC release, a significant change has been introduced which
allows you to use C++11 features such as std::thread that rely on the POSIX
threading library. TDM-GCC now includes a new pthreads compatibility layer
called "winpthreads" instead of the old "pthreads-w32".

"winpthreads" is one of the libraries distributed by the MinGW-w64 project, and
it allows GCC to be compiled with full pthreads compatibility, which is
necessary to enable std::thread and other threading related functions in the
C++ runtime.

Because of TDM-GCC's continuing goal of minimizing extra DLLs, winpthreads has
been compiled statically.
It will be statically linked with every program you
compile, which will increase your baseline executable size.

The same mechanism used in libgcc and libstdc++ to allow EXEs and DLLs to share
state for handling exceptions has also been patched into winpthreads to allow
your EXEs and DLLs to share C++11 thread handles via the underlying pthread
handles.

Because every program you compile will now rely on winpthreads, you should make
sure to read and comply with its MIT-style license, included in the file
"COPYING.winpthreads.txt".
<END QUOTE>

TDM-GCC comes in 32 and 64 bit distributions, and although it is not affiliated to the Mingw project, it is an excellent distribution.

Nicholas.
Reply all
Reply to author
Forward
0 new messages