I’m building an OCaml project with Dune on Windows and the resulting .exe depends on libgmp-10.dll which I eventually found (turns out Windows doesn’t have anything like ldd but you can instead just do where libgmp-10.dll) here: C:\Users\Tim\AppData\Local\opam\.cygwin\root\usr\x86_64-w64-mingw32\sys-root\mingw\bin\libgmp-10.dll
I’d like to statically link it instead. I found that cygwin does install a static library here: "C:\Users\Tim\AppData\Local\opam\.cygwin\root\usr\x86_64-w64-mingw32\sys-root\mingw\lib\libgmp.a", but how do I tell Dune (or Opam?) to use that instead?
You will need to figure out the exact flags to pass to the linker. If the dependency on libgmp is coming from a library that links with it, you should look at using that library’s stanza (library_flags). Passing the static .a archive directly on the linker command line using -cclib (instead of using -lgmp) may be enough.
Sorry for the vagueness, but there are so many factors involved in linking and so many different contexts involved (OCaml, C, Mingw, Windows, …) that it is hard to give a solution without sitting down and trying things out But I believe that it should be feasible to achieve what you want.
Hmm I think the dependency comes from Zarith and that seems to be hardcoded to use -lgmp… so I guess there’s no way to do this (other than forking Zarith I guess)?
There may be a branch with libtommath support, which is discussed in a Zarith PR. The reason given for the libtommath backend was to do with compiling with MSVC on Windows. That’s not what you asked about, but it seems relevant and might be interesting to you. Libtommath also has a more permissive license wrt static linking, in case that matters to you.
Yet another option, but which involves less forking of packages, is to ship the DLLs, but use application manifests to ensure your executable definitely uses the ones you’re after. opam has a mode to build this way (code in opam/src/manifest at master · ocaml/opam · GitHub - it’s enabled when building by passing --with-private-runtime to opam’s configure script IIRC). opam also supports building its executable statically on Windows, so it’s a demo for that as well!
One of my (many) post-relocatable-OCaml dreams is to be able to select between static and shared linking of libraries elegantly… one day!
Sorry, that wasn’t meant to suggest it was a dependency - I meant that the static/shared linking saga is something I’ve worked on improving in the past, and hope to return to at some point, not being bogged down in relocatable OCaml stuff! (I was also involved in that blog post…)