Hi there!
I am writing an ocaml wrapper for an existing windows library. I have a .h and a .lib. I don’t know which compiler has been used to produce the .lib, most likely cl.
I’m using the Ocaml for windows environment, which comes with recent versions of ocaml and opam, as well as a pre-configured C.compiler:
$ $CC --version x86_64-w64-mingw32-gcc (GCC) 9.2.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I can build and link my stubs and library correctly. However, at execution time, I get a segfault. I did a minimum example with just a single C file and my library, compiled with the provided $CC: still a segfault.
I then downloaded another C compiler (TDM GCC). I’ve compiled my minimal C example: it works !
So I’ve tried to use this C compiler for ocamlopt, by putting the following dune file at the root of my project:
(env (_ (ocamlopt_flags (-cc gcc)) ) )
Hélas, when I build, it does not find flexdll symbols:
$ dune build tests/api/main.exe ocamlopt tests/api/main.exe (exit 2) (cd _build/default && C:\OCaml64\home\XXXXX\.opam\4.10.0+mingw64c\bin\ocamlopt.opt.exe -w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths -keep-locs -cc gcc -o tests/api/main.exe src/api/api.cmxa -I src/api -I src/api/lib tests/api/.main.eobjs/native/dune__exe__Main.cmx) C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/OCaml64/home/amonnier/.opam/4.10.0+mingw64c/lib/ocaml\libasmrun.a(win32_n.o): in function `caml_dlopen': /home/appveyor/.opam/ocaml-variants.4.10.0+mingw64c/.opam-switch/build/ocaml-variants.4.10.0+mingw64/runtime/win32.c:232: undefined reference to `flexdll_wdlopen'
[… similarly missing symbols: flexdll_wdlopen, flexdll_dump_exports, flexdll_dlopen, flexdll_dlclose, flexdll_dlsym, flexdll_dlerror]
/lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main': C:/crossdev/src/mingw-w64-v7-git20191109/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status File "caml_startup", line 1: Error: Error during linking
I’m running short of ideas: does it make sense to try to use this other compiler ? are there extra flags needed to tell it where to find these flexdll and WinMain symbols ? And why the hell do I get a segfault with $CC and not with gcc ?
Any clue will be deeply appreciated,