Flexlink error when compiling OCaml 4.07.1 on Windows 10

build
windows

#1

I am learning how to compile OCaml 4.07.1 on Windows 10. make world and make world.opt both fail with the following error:

make -C byterun  all
make[1]: Entering directory '/home/ci/ocaml-4.07.1/byterun'
flexlink -x64 -merge-manifest -stack 33554432 -exe -link "/ENTRY:wmainCRTStartup" -o ocamlrun.exe prims.obj libcamlrun.lib advapi32.lib ws2_32.lib version.lib
** Cannot resolve symbols for descriptor object:
 __iob_func
 sprintf
make[1]: *** [Makefile:187: ocamlrun.exe] Error 2
make[1]: Leaving directory '/home/ci/ocaml-4.07.1/byterun'
make: *** [Makefile:389: coldstart] Error 2

I am under Windows 10 (1809, OS build 17763.316) with Visual Studio Community 2017.
cl displays Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27027.1 for x64.
flexlink displays FlexDLL version 0.37.
I have the following cygwin packages installed:

$ cygcheck -c
Cygwin Package Information
Package              Version             Status
_autorebase          001007-1            OK
alternatives         1.3.30c-10          OK
autoconf             13-1                OK
autoconf2.1          2.13-12             OK
autoconf2.5          2.69-4              OK
automake             10-1                OK
automake1.10         1.10.3-3            OK
automake1.11         1.11.6-3            OK
automake1.12         1.12.6-3            OK
automake1.13         1.13.4-2            OK
automake1.14         1.14.1-3            OK
automake1.15         1.15.1-1            OK
automake1.9          1.9.6-11            OK
base-cygwin          3.8-1               OK
base-files           4.2-4               OK
bash                 4.4.12-3            OK
bzip2                1.0.6-3             OK
ca-certificates      2.22-1              OK
coreutils            8.26-2              OK
cygutils             1.4.16-2            OK
cygwin               3.0.1-1             OK
dash                 0.5.9.1-1           OK
diffutils            3.5-2               OK
editrights           1.03-1              OK
file                 5.32-1              OK
findutils            4.6.0-1             OK
gawk                 4.2.1-1             OK
getent               2.18.90-4           OK
grep                 3.0-2               OK
groff                1.22.3-1            OK
gzip                 1.8-1               OK
hostname             3.13-1              OK
info                 6.5-2               OK
ipc-utils            1.0-2               OK
less                 530-1               OK
libargp              20110921-3          OK
libattr1             2.4.48-2            OK
libblkid1            2.32.1-1            OK
libbz2_1             1.0.6-3             OK
libcrypt0            2.1-1               OK
libdb5.3             5.3.28-2            OK
libfdisk1            2.32.1-1            OK
libffi6              3.2.1-2             OK
libgc1               7.6.10-1            OK
libgcc1              7.4.0-1             OK
libgdbm4             1.12-1              OK
libgmp10             6.1.2-1             OK
libguile2.0_22       2.0.14-3            OK
libiconv             1.14-3              OK
libiconv2            1.14-3              OK
libintl8             0.19.8.1-2          OK
libltdl7             2.4.6-6             OK
liblzma5             5.2.3-1             OK
libmpfr6             4.0.2-1             OK
libncursesw10        6.0-12.20171125     OK
libopenssl100        1.0.2p-1            OK
libp11-kit0          0.23.10-1           OK
libpcre1             8.40-3              OK
libpipeline1         1.4.0-1             OK
libpopt-common       1.16-2              OK
libpopt0             1.16-2              OK
libreadline7         7.0.3-3             OK
libsigsegv2          2.10-2              OK
libsmartcols1        2.32.1-1            OK
libssp0              6.4.0-4             OK
libstdc++6           7.4.0-1             OK
libtasn1_6           4.13-1              OK
libunistring2        0.9.10-1            OK
libuuid1             2.32.1-1            OK
login                1.12-1              OK
m4                   1.4.18-1            OK
make                 4.2.1-2             OK
man-db               2.7.6.1-1           OK
mintty               2.9.6-0             OK
ncurses              6.0-12.20171125     OK
openssl              1.0.2p-1            OK
p11-kit              0.23.10-1           OK
p11-kit-trust        0.23.10-1           OK
perl                 5.26.3-1            OK
perl-Carp            1.38-2              OK
perl-Test-Harness    3.42-1              OK
perl_autorebase      5.26.3-1            OK
perl_base            5.26.3-1            OK
rebase               4.4.4-1             OK
run                  1.3.4-2             OK
sed                  4.4-1               OK
tar                  1.29-1              OK
terminfo             6.0-12.20171125     OK
texinfo              6.5-2               OK
tzcode               2018i-1             OK
tzdata               2018i-1             OK
util-linux           2.32.1-1            OK
vim-minimal          8.0.1567-1          OK
which                2.20-2              OK
xz                   5.2.3-1             OK
zlib0                1.2.11-1            OK

Thank you for any help!


#2

In esy we build OCaml compiler on Windows using mingw toolchain.

We do have a fork of flexdll though but as far as I know most of the fixes are related to long file path on Windows + a fix for linking C++ code.

I’m not an expert here, @bryphe did this and knows better.


#3

Huh, and people were telling me OCaml works smoothly on Windows: OCaml and Windows


#4

Thank you for suggesting mingw. Unfortunately, I just tried and got the same error with mingw.


#5

Looks like a related issue: https://caml.inria.fr/mantis/view.php?id=7263

(are you sure it picked mingw toolchain and not msvc again?)


#6

Thank you very much for exhuming this issue: that makes me realize that I missed the paragraph in README.win32.adoc telling that to use recent versions of Visual Studio, I have to bootstrap flexdll (I was using the binary version distributed by @alainfrisch).

It works much better now… but make world still fails at

../../boot/ocamlrun ../../tools/ocamlmklib -oc unix accept.obj bind.obj channels.obj close.obj
close_on.obj connect.obj createprocess.obj dup.obj dup2.obj errmsg.obj envir.obj getpeername.ob
j getpid.obj getsockname.obj gettimeofday.obj isatty.obj link.obj listen.obj lockf.obj lseek.ob
j nonblock.obj mkdir.obj mmap.obj open.obj pipe.obj read.obj readlink.obj rename.obj select.obj
 sendrecv.obj shutdown.obj sleep.obj socket.obj sockopt.obj startup.obj stat.obj symlink.obj sy
stem.obj times.obj unixsupport.obj windir.obj winwait.obj write.obj winlist.obj winworker.obj w
indbug.obj utimes.obj access.obj addrofstr.obj chdir.obj chmod.obj cst2constr.obj cstringv.obj
execv.obj execve.obj execvp.obj exit.obj getaddrinfo.obj getcwd.obj gethost.obj gethostname.obj
 getnameinfo.obj getproto.obj getserv.obj gmtime.obj mmap_ba.obj putenv.obj rmdir.obj socketadd
r.obj strofaddr.obj time.obj unlink.obj -ldopt ws2_32.lib -ldopt advapi32.lib
'..\..\boot\ocamlrun' is not recognized as an internal or external command,
operable program or batch file.

make world.opt fails with a similar error. I found this issue https://caml.inria.fr/mantis/view.php?id=408 but it does not seem to be the same problem, since I do have a file boot/ocamlrun.exe, which is executable and which works properly.


#7

Your original problem is due to the fact that flexdll includes a small runtime support library, and the binary version is compiled with a Visual Studio < 2015 which is not binary compatible with VS >= 2015.

You have two options:

  1. Re-compile flexdll from source and use that when compiling OCaml
  2. Compile OCaml with the “bootstrapped” flexdll

Option 2. is easier and should work. Just make sure to start from a clean repository and build things in the right order: make flexdll; make world.opt.


#8

This error is a bit strange because it is a cmd.exe error, which you should not get if you are building under Cygwin.