I want to compile some OCaml bytecode and have it run on Windows and Unix-type systems. My source code works fine if I recompile it on each platform, but the bytecode isn't portable.

Sample code:

open Unix

let on_windows = Filename.dir_sep <> "/";;
Printf.printf "On windows: %b\n" on_windows;;

let child = create_process "gpg" (Array.of_list ["gpg"; "--version"]) stdin stdout stderr;;
Printf.printf "Child %d\n" child;;

Build command:

ocamlbuild -use-ocamlfind -pkg unix test.byte

If I compile on Windows and run on Linux, I get

Fatal error: unknown C primitive `win_waitpid'

If I compile on Linux and run on Windows I get:

Fatal error: unknown C primitive `unix_waitpid'

How can I make the bytecode work everywhere?

Edit
Report