Open polytypic opened 1 year ago
I made an experiment to try to use Ctypes to link to a custom DLL on Windows such that the result OCaml library could be loaded in the OCaml toplevel on Windows. It seems to work! (~Well, building via opam pin . -y
still fails for some reason. That seems to be a problem with a specific OCaml switch.~)
With an ugly hack to use flexlink
in dune (replacing libtool
invocation)
(bash
"x86_64-w64-mingw32-ar rcs libuv.a `find src -path '*/.libs/*.o'`")
(bash
"flexlink -chain mingw64 -o dlluv.dll `find src -path '*/.libs/*.o'`")
and manual addition of two prototypes with __declspec(dllimport)
extern __declspec(dllimport) _NETIOAPI_SUCCESS_ NETIOAPI_API ConvertInterfaceIndexToLuid(
NET_IFINDEX InterfaceIndex,
PNET_LUID InterfaceLuid
);
extern __declspec(dllimport) _NETIOAPI_SUCCESS_ NETIOAPI_API ConvertInterfaceLuidToNameW(
const NET_LUID *InterfaceLuid,
PWSTR InterfaceName,
SIZE_T Length
);
I managed to build luv
such that I could #require "luv"
in Windows:
C:\Users\polytypic\work\luv>dune utop
────────────────────────┬──────────────────────────────────────────────────────────────┬────────────────────────
│ Welcome to utop version 2.10.0 (using OCaml version 4.14.0)! │
└──────────────────────────────────────────────────────────────┘
Type #utop_help for help about using utop.
─( 15:18:20 )─< command 0 >──────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop # #require "luv";;
─( 15:18:21 )─< command 1 >──────────────────────────────────────────────────────────────────────{ counter: 0 }─
utop #
Obviously some fine tuning is needed for a proper PR.
An attempt to
#require "luv"
in OCaml toplevel fails on Windows. Here is sample output:The same seems to happen with other OCaml tools (I've tested utop and mdx) that run OCaml bytecode and also with other OCaml versions (I've tested with 5.0.0).
The
No master relocation table
message seems to point toflexdll
which is used by OCaml on Windows.I don't know how to exactly fix this problem, but my understanding is that with
flexdll
one needs to link applications and libraries using the specialflexlink
tool.