I'm trying to cross-compile a program which uses pthreads to windows using nix and mingw.
The build complains about missing headers (pthread.h), even though i set windows.pthreads
as a buildInput.
windows.pthreads
seems to only copy libpthreadGC2.a
and ignore the headers. (source)
win.nix:
{ pkgs ? import (builtins.fetchTarball "https://github.com/nixos/nixpkgs/archive/nixos-23.05.tar.gz") { } }:
let
source = pkgs.writeText "main.c" ''
#include <pthread.h>
int main() {
return 0;
}
'';
package = { runCommandCC, fetchurl, stdenv, windows }: runCommandCC "test" {
buildInputs = [ windows.pthreads ];
} ''
mkdir $out
cd $out
cd $out
$CC -pthread ${source} -o main
'';
in
pkgs.pkgsCross.mingw32.callPackage package { }
Compilation:
nix-build win.nix
this derivation will be built:
/nix/store/7cwz7v404nm51i34avfqpvzz4mm2r7mb-test-i686-w64-mingw32.drv
building '/nix/store/7cwz7v404nm51i34avfqpvzz4mm2r7mb-test-i686-w64-mingw32.drv'...
/nix/store/11635lqa2ad8225ahky756pmj5fv81kl-main.c:1:10: fatal error: pthread.h: No such file or directory
1 | #include <pthread.h>
| ^~~~~~~~~~~
compilation terminated.