You are not doing anything incorrect, Mingw-Builds works that way you.
I recently stumbled on this, but for another reason:
Mingw-Builds automatically links executables to GCC dynamic libraries (libwinpthread-1.dll,
libstdc++-6.dll, libgcc_s_dw2-1.dll) to save executable size (problem: when you release executables you have to remember to add missing dlls too along with your binary because there's no guarantee users have those DLL on their systems)
In my case the problem was that I had multiple GCC pakcages on the same system and hence I not added them to PATH to avoid name clashes.
The fun part is that CMAKE before configuring your project generates a C-SourceFile that is compiled and used to get informations about your compiler, since DLLs were not in PATH, that small executable generated by CMake was crashing because of missing DLLs and that stopped the whole build process.
The solution to fix that is adding the compiler path to PATH TEMPORARILY (or better run CMake in another environment).
Adding DLLs manually to the Cmake temp directory doesn't work because Cmake cleanup that directory at each configuration..
If you use mingwbuilds you have to link to pthreadBLAH.dll no workaround
-Bstatic
option doesn't seem to work, but you can probably get what you want by specifying the specific library file instead of lettingld
search for it: https://mcmap.net/q/1018735/-how-to-force-ld-to-use-a-static-lib-instead-of-shared-lib – Horizontallibpthread.a
(yes, the dynamic one islibwinpthread-1.dll
too), therefore I'd rather use-lpthread
. Probably the same is valid for yours. – Chauffer