mingw-cross-env-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Static pthread library in shared toolchain


From: david.chappaz
Subject: Static pthread library in shared toolchain
Date: Mon, 23 Aug 2021 10:31:18 -0700

Hi,

 

I wish I had discovered MXE earlier !

For some time I’ve been using a fairly manual process to build my Cross-Compiler toolchains, largely based on scripts (like this one: https://sourceforge.net/p/mingw-w64/discussion/723797/thread/ea9a5b00fb/#a77a/8f8e/df3a/fd2e/daae/98f0/1491)

 

Yesterday, for the first time I built a toolchain using MXE and it was a breeze !

 

I have a few questions and need a few clarifications though. I built my toolchains as follows:

 

make MXE_TARGETS=x86_64-w64-mingw32.shared x86_64-w64-mingw32.static’ MXE_PLUGIN_DIRS=plugins/gcc6 pthreads

 

At this point, my lack of detailed understanding will probably show….

 

My understanding is that the ’static’ toolchain is a *** subset *** of the ’shared’ one.

In other words, while the ’static’ toolchain only supports static link (which is a guarantee produce completely standalone executables), the ’shared’ toolchain supports both dynamic link *** and *** static link.

Is that correct ?

 

As a matter of fact, this expectation is consistent with what I see:

  • mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/6.3.0    contains both:
    • libstdc++.dll.a
    • libstdc++.a
  • mxe/usr/lib/gcc/x86_64-w64-mingw32.static/6.3.0     only contains:
    • libstdc++.a

 

The same comment applies to plenty other libraries, for example libquadmath, libatomic, etc…

So far so good.

 

Now looking a bit more in depth, I also see that

  • mxe/usr/x86_64-w64-mingw32.shared/lib   only contains:
    • libpthread.dll.a & libwinpthread.dll.a
  • mxe usr/x86_64-w64-mingw32.static/lib     only contains:
    • libpthread.a & libwinpthread.a

 

The above is what surprises me a bit.

  • Why does the ’shared’ toolchain not contain the static version of libpthread and libwinpthread by default ?
    • Due to a circular dependency between libstdc++ and libpthread, this is (I believe) the only aspect that prevents the ’shared’ toolchain from producing static builds:

 

            $ x86_64-w64-mingw32.shared-g++ -static main.cpp -o main.exe
            x86_64-w64-mingw32.shared-ld: cannot find -lpthread

 

    • As expected, the problem goes away if I copy libpthread.a & libwinpthread.a from mxe usr/x86_64-w64-mingw32.static/lib to mxe usr/x86_64-w64-mingw32.shared/lib

 

  • Are there specific command line arguments to force the generation of these static libraries (for the ’shared’ toolchain) ?

 

Thanks a lot for any feedback and clarifications !

David


reply via email to

[Prev in Thread] Current Thread [Next in Thread]