Open ppigazzini opened 2 years ago
Hi,
I have encountered the exact same issue while trying to compile QuickJS on Windows 11 (zig 0.9.1)
zig build
error(compilation): clang failed with stderr: .\src\QuickJS\quickjs.c:113:10: fatal error: 'pthread.h' file not found
.\src\QuickJS\quickjs.c:1:1: error: unable to build C object: clang exited with code 1
Any workarounds available?
Bump, I am also trying to compile something with pthread on Windows.
Mingw does provide libpthread but the sub library is not included in zig redistribution of it. https://github.com/mirror/mingw-w64/tree/master/mingw-w64-libraries/winpthreads
In ArchLinux, I installed mingw-w64-winpthreads, and added below code in build.zig
main.addIncludeDir("/usr/x86_64-w64-mingw32/include");
main.addObjectFile("/usr/x86_64-w64-mingw32/lib/libpthread.a");
it builds successfully for windows binary, and runs without problem.
In ArchLinux, I installed mingw-w64-winpthreads, and added below code in build.zig
main.addIncludeDir("/usr/x86_64-w64-mingw32/include");
main.addObjectFile("/usr/x86_64-w64-mingw32/lib/libpthread.a");
it builds successfully for windows binary, and runs without problem.
Same here with msys2!! Except, add includePath, only copy pthread headers.
Why?
Conflicts (headers): (gnu vs libcxx)
0MQ need pthread.h
and link to msys2/mingw-w64-ucrt-x86_64
else:
https://github.com/kassane/libzmq/actions/runs/4387226215/jobs/7682267122#step:5:1
Run zig build bench_rt -Doptimize=ReleaseFast -Dperf
error(compilation): clang failed with stderr: D:\a\libzmq\libzmq\src\thread.cpp:40:10: fatal error: 'pthread.h' file not found
D:\a\libzmq\libzmq\src\thread.cpp:1:1: error: unable to build C object: clang exited with code 1
error: zmq...
https://github.com/kassane/winpthreads-zigbuild
CI: https://github.com/kassane/winpthreads-zigbuild/actions/runs/4544384380/jobs/8010328190
zig build test_nanosleep -DTests=true -DShared=false -Doptimize=ReleaseSafe
1680014539.456163100
1680014540.458370200
sleep 1002 ms
nanosleep succeeded.
nanosleep succeeded.
nanosleep succeeded.
nanosleep succeeded.
nanosleep succeeded.
[1680014546.477188300] clock_gettime (CLOCK_REALTIME)
[ 993.099409700] clock_gettime (CLOCK_MONOTONIC)
[ 0.000000000] clock_gettime (CLOCK_PROCESS_CPUTIME_ID)
[ 0.000000000] clock_gettime (CLOCK_THREAD_CPUTIME_ID)
[1680014547.484434200] clock_gettime (CLOCK_REALTIME)
[ 994.106632800] clock_gettime (CLOCK_MONOTONIC)
[ 0.000000000] clock_gettime (CLOCK_PROCESS_CPUTIME_ID)
[ 0.000000000] clock_gettime (CLOCK_THREAD_CPUTIME_ID)
@andrewrk can you confirm if this is something we want? I can do the work, but I wonder if it was a deliberate choice to omit winpthreads.
Zig Version
0.9.1
Steps to Reproduce
Expected Behavior
Make a cross build with target Windows.
Notes:
x86_64-linux-musl
,aarch64-linux-musl
)Actual Behavior
The mingw-w64 shipped with Zig misses
pthread.h
, I don't know if this is intended. The wiki instructions to update mingw-w64 fail when configuringmingw-w64-crt
(and skipsmingw-w64-winpthreads
) so I built mingw-w64 using this script: https://github.com/Zeranoe/mingw-w64-build However after updating Zig with the new mingw-w64 headers I got errors/conflicts with somelibcxx
files.