I’ve been trying to build rust on Windows for a while now, and it keeps failing. The build was failing at first due to this issue, but apparently running make after that should succeed. In my case however, it would fail again, and again, with an error ld.exe: cannot find -lpthread
. I searched high and low for someone else with the same error, but most people were having undefined references in pthread since they were linking the library before linking the object file that actually references pthread. After spending some time on IRC, I discovered that it wasn’t an issue with rust itself, simply trying to compile and link a basic C program with -lpthread
would give the same error.
Now, the rust documentation recommends installing mingw32-libpthread-old
, and that’s what I had done. But while digging around in the packages provided by mingw I discovered a package named mingw32-pthreads-w32
. And I remembered that a while back, rust would require an older version of gcc in order to compile successfully on Windows, and so the mingw32-libpthread-old
package was probably a dependency for the older gcc that somebody forgot to remove from the documentation. I installed the newer version of pthread from the mingw installer, and rust built successfully!
Also, this post is probably already irrelevant, since 11 hours back a pull-request was merged into rust that stops linking pthread into rust and opts to use the native win32 threading library instead, but I figured I might as well put this up for posterity.