This is indeed a strange effect - bluntly, flexlink should be bootstrapped with the OCaml sources (i.e. a bytecode image of flexlink should be in /boot). Note that your Cygwin build-route really is missing a step - you're bootstrapping, so the final stage should be recompiling flexlink using your new ocamlopt (the compilers do indeed need flexlink), then the dependency on Cygwin disappears. For my own builds, I extract flexlink.exe from Alain's binary distribution, build the FlexDLL objects from sources, compile OCaml and then recompile flexlink.exe using the that fresh compiler and replace the earlier binary copy. See, for example, https://github.com/dra27/OCaml-Windows-Build/blob/master/build.cmd#L527-L570 At some point, I was going to alter things so that FlexDLL is the only requirement for pre-installation (as that can be built from source) and have the ocaml process use boot/flexlink if a binary flexlink isn't available... but as that's only to satisfy a religious fervour to remove the circular dependency, it's right down at the bottom of my personal task list, especially as I doubt it would be merged :o) Regarding the reason for FlexDLL, the solution for tricking the linker does also work for gcc - see http://edll.sourceforge.net/#def_a (which is referenced from FlexDLL's webpage). I expect Alain's motivation for FlexDLL is that the "side-effects" referred to in http://alain.frisch.fr/flexdll.html#examples were known about beforehand which the .def/.a solution doesn't solve, especially as it makes the build process more complicated. David From: caml-list-request@inria.fr [mailto:caml-list-request@inria.fr] On Behalf Of Soegtrop, Michael Sent: 24 October 2015 10:51 To: caml-list@inria.fr Subject: [Caml-list] flexdll circular dependency on ocamlc: Impossible to built ocaml for mingw without using some prebuilt binaries? Dear Ocaml Users, building Ocaml for Mingw on Cygwin I came across a strange effect: flexdll (or flexlink) depends on the Ocaml compiler and the Ocaml compiler depends on flexdll. I wonder how one is supposed to build Ocaml for Mingw from scratch? One either needs prebuilt flexdll/flexlink or Ocaml. What does work is to first build a native Cygwin Ocaml, then flexlink using this one and then the MingW Ocaml, but then flexlink depends on the Cygwin dlls. I am not sure how bad this is but I think ocamlc needs flexlink later as well when linking MingW apps. Also the effort of this is rather high. So I used a prebuilt flexlink/flexdll but I don't really like this. Also I wonder why flexdll/flexlink is required. The documentation of flexdll states: Windows DLL cannot refer to symbols defined in the main application or in previously loaded DLLs. In my experience this is not true. At least when using MSVC one can declare functions in the main executable as DLL-export. Then when linking the main executable an import library is created in the same way as when building a DLL by the linker. The DLL can then link to this import library and can access the functions in the main executable. The same is true for any other dlls already loaded. I don't do this every day but I did this more than once. I am not sure if this also works on old Windows OSes. I think the oldest one on which I tested this is Windows 7. Also I don't know if gcc does support creating an import library when linking an executable. If this is of interest, I could provide a small demo for this and also test it with gcc for mingw and, if someone thinks this is useful, also on XP and Vista. Best regards, Michael Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Prof. Dr. Hermann Eul Chairperson of the Supervisory Board: Tiffany Doon Silva Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928