build.cpp: -pthread is added on Windows and breaks the MinGW link (-lpthread) #67

Closed
opened 2026-12-06 06:12:02 +00:00 by faumaray · 1 comment
Owner

Context

Cross-building VBS for the Windows target through the native VBS build path (vbs install --target-os windows) fails while linking vbs.exe:

x86_64-w64-mingw32-ld.bfd: cannot find -lpthread: No such file or directory
collect2: error: ld returned 1 exit status

Cause

build.cpp adds -pthread (compile and link) to the System/SystemAsync/CryptoAsync/SecurityAsync module targets unconditionally:

} else if (module == "CryptoAsync" || module == "SecurityAsync" ||
           module == "System" || module == "SystemAsync") {
    target.compile_option("-pthread", Visibility::Public);
    target.link_option("-pthread", Visibility::Public);
}

On MinGW-w64 the driver expands -pthread to -lpthread, which does not exist there (the runtime is libwinpthread/-pthread is not provided as libpthread.a in every toolchain). The CMake build links fine because Threads::Threads is empty/handled by CMake on Windows, but the native description propagates the raw flag.

Request

Guard the pthread options with if (!windows) (the runtime section already does this at line ~810), or use the platform-appropriate thread flags on Windows.

Reproduced with MinGW-w64 GCC 16.2 UCRT via the VBS self-hosted install of Void/Build-System at pin de1fdcda.

## Context Cross-building VBS for the Windows target through the native VBS build path (`vbs install --target-os windows`) fails while linking `vbs.exe`: ``` x86_64-w64-mingw32-ld.bfd: cannot find -lpthread: No such file or directory collect2: error: ld returned 1 exit status ``` ## Cause `build.cpp` adds `-pthread` (compile and link) to the `System`/`SystemAsync`/`CryptoAsync`/`SecurityAsync` module targets unconditionally: ```cpp } else if (module == "CryptoAsync" || module == "SecurityAsync" || module == "System" || module == "SystemAsync") { target.compile_option("-pthread", Visibility::Public); target.link_option("-pthread", Visibility::Public); } ``` On MinGW-w64 the driver expands `-pthread` to `-lpthread`, which does not exist there (the runtime is `libwinpthread`/`-pthread` is not provided as `libpthread.a` in every toolchain). The CMake build links fine because `Threads::Threads` is empty/handled by CMake on Windows, but the native description propagates the raw flag. ## Request Guard the pthread options with `if (!windows)` (the runtime section already does this at line ~810), or use the platform-appropriate thread flags on Windows. Reproduced with MinGW-w64 GCC 16.2 UCRT via the VBS self-hosted install of Void/Build-System at pin `de1fdcda`.
Author
Owner

Fixed on main in 1b19473. -pthread is now only added when !windows, for the System/SystemAsync/CryptoAsync/SecurityAsync targets and for Net. The target OS comparison is case-insensitive too.

Fixed on main in 1b19473. `-pthread` is now only added when `!windows`, for the System/SystemAsync/CryptoAsync/SecurityAsync targets and for Net. The target OS comparison is case-insensitive too.
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Void/Library#67