How to statically link without cygwin1.dll(under Windows)?

#1

I used to use http://protz.github.io/ocaml-installer/ which generates native standalone binaries which can run under CMD or powershell.
After upgrade to 4.06, there is no such installer any more, I tried to install from source, everything works except that generated exe can only run under cygwin since it require cygwin1.dll? Is there any way to generate exes under Windows without dependency on cygwin?
Thanks

0 Likes

#2

Since you compiled from source, you certainly read the release notes for the Microsoft Windows ports of OCaml (https://github.com/ocaml/ocaml/blob/trunk/README.win32.adoc)?

Do not confuse the environment used to compile them with the different ports. By instance, you can compile the Native Mingw-w64 port from within cygwin, whithout restrictions on the generated executables.

[I replied by email, but one sentence is missing. I’m manually adding it here:] From my own experience, I would recommend to use the excellent “Ocaml for windows” (https://fdopen.github.io/opam-repository-mingw/).

Best regards

0 Likes

#3

To generate native Windows binaries (that do not depend on the Cygwin DLL) you have two options, depending which toolchain you want to use:

  1. use the native Microsoft toolchain (compiler: cl)
  2. use the mingw-w64 toolchain (compiler: gcc)

To use 1., configure as follows:

./configure --build=x86_64-unknown-cygwin --host=x86_64-pc-windows

To use 2.:

./configure --build=x86_64-unknown-cygwin --host=x86_64-w64-mingw32

(with some variations if you want output 32 bit binaries). Full details at https://github.com/ocaml/ocaml/blob/trunk/README.win32.adoc

1 Like

#4

I get an errror after set --host option, --build option does not work.

Hongbo Zhang@DESKTOP-PCMUAKU /cygdrive/c/ocaml406/ocaml-4.06.1
$ ./configure --prefix /cygdrive/c/ocaml406/ocaml-4.06.1 --host x86_64-w64-mingw32 && make world.opt
Configuring OCaml version 4.06.1
Configuring for host x86_64-w64-mingw32 ...
Configuring for target x86_64-w64-mingw32 ...
Using compiler gcc.
Compiler family and version: gcc-7-4.
The C compiler is ISO C99 compliant.
Checking the sizes of integers and pointers...
Wow! A 64 bit architecture!
This is a little-endian architecture.
Doubles can be word-aligned.
Adding -fno-tree-vrp option to work around PR#7452
ranlib found
#! appears to work in shell scripts.
We won't use it, though, because it's on the target platform  it would be used and windows doesn't support it.
POSIX signal handling found.
expm1(), log1p(), hypot(), copysign() found.
getrusage() found.
times() found.
secure_getenv() found.
issetugid() found.
termcap functions found (with libraries '-lcurses')
You have BSD sockets.
socklen_t is defined in <sys/socket.h>
inet_aton() found.
IPv6 is supported.
stdint.h found.
unistd.h found.
off_t is defined in <sys/types.h>
dirent.h found.
rewinddir() found.
lockf() found.
mkfifo() found.
getcwd() found.
getpriority() found.
utime() found.
utimes() found.
dup2() found.
fchmod() found.
truncate() found.
sys/select.h found.
select() found.
nanosleep() found.
symlink() found.
waitpid() found.
wait4() found.
getgroups() found.
initgroups() found.
POSIX termios found.
setitimer() found.
gethostname() found.
uname() found.
gettimeofday() found.
mktime() found.
setsid() found.
putenv() found.
setlocale() and <locale.h> found.
dlopen() found.
Dynamic loading of shared libraries is supported.
mmap() found.
pwrite() found
stat() supports nanosecond precision.
mkstemp() found
nice() found
dup3() found
pipe2() found
accept4() found
sys/shm.h found.
execvpe() found.
Replay debugger supported.
Cannot detect system stack overflow.
POSIX threads library supported.
Options for linking with POSIX threads: -lpthread
sigwait() found
Bytecode threads library supported.
X11 works
Options for compiling for X11:
Options for linking with X11: -lX11
BFD library found.
[WARNING] Could not determine link options for the BFD library
Assembler supports CFI

** Configuration summary **

Directories where OCaml will be installed:
        binaries.................. /cygdrive/c/ocaml406/ocaml-4.06.1/bin
        standard library.......... /cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml
        manual pages.............. /cygdrive/c/ocaml406/ocaml-4.06.1/man (with extension .1)
Configuration for the bytecode compiler:
        C compiler used........... gcc
        options for compiling..... -O2 -fno-strict-aliasing -fwrapv
        options for linking.......   -lm  -lcurses -lpthread
        shared libraries are supported
        options for compiling.....  -O2 -fno-strict-aliasing -fwrapv
        command for building...... flexlink -chain mingw64 -merge-manifest -stack 16777216 -o lib.so /a/path objs
Configuration for the native-code compiler:
        hardware architecture..... amd64
        OS variant................ mingw
        C compiler used........... gcc
        options for compiling..... -O2 -fno-strict-aliasing -fwrapv
        options for linking.......  -lm
        assembler ................ as
        preprocessed assembler ... gcc -c
        assembler supports CFI ... yes
        with frame pointers....... no
        naked pointers forbidden.. no
        spacetime profiling....... no
        reserved bits in header... no
        C plugins................. no
        compile with -fPIC........ no
        native dynlink ........... true
        profiling with gprof ..... not supported
        using flambda middle-end . no
        force safe strings ............. no
        (-safe-string is the default per-file option)
        flat float arrays ........ yes
        afl-fuzz always enabled .. no
Source-level replay debugger: supported
Additional libraries supported:
        win32unix str dynlink bigarray raw_spacetime_lib systhreads threads graph
Configuration for the "graph" library:
        options for compiling ....
        options for linking ...... -lX11

** OCaml configuration completed successfully **

make -C byterun  all
make[1]: Entering directory '/cygdrive/c/ocaml406/ocaml-4.06.1/byterun'
echo "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml/stublibs" > ld.conf
echo "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml" >> ld.conf
sed -n -e '/^  /s/ \([A-Z]\)/ \&\&lbl_\1/gp' \
       -e '/^}/q' caml/instruct.h > caml/jumptbl.h
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  interp.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from interp.c:20:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
../tools/make-version-header.sh ../VERSION > caml/version.h
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  misc.c
In file included from caml/config.h:23:0,
                 from misc.c:21:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  stacks.c
In file included from caml/config.h:23:0,
                 from stacks.c:21:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  fix_code.c
In file included from caml/config.h:23:0,
                 from fix_code.c:20:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  startup_aux.c
In file included from caml/config.h:23:0,
                 from caml/mlvalues.h:22,
                 from caml/backtrace.h:21,
                 from startup_aux.c:22:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  startup.c
In file included from caml/config.h:23:0,
                 from startup.c:24:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  freelist.c
In file included from caml/config.h:23:0,
                 from freelist.c:25:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  major_gc.c
In file included from caml/config.h:23:0,
                 from caml/compact.h:21,
                 from major_gc.c:21:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  minor_gc.c
In file included from caml/config.h:23:0,
                 from caml/mlvalues.h:22,
                 from caml/custom.h:23,
                 from minor_gc.c:19:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  memory.c
In file included from caml/config.h:23:0,
                 from caml/address_class.h:21,
                 from memory.c:22:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  alloc.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from alloc.c:24:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  roots.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/roots.h:21,
                 from caml/finalise.h:21,
                 from roots.c:20:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  globroots.c
In file included from caml/config.h:23:0,
                 from caml/memory.h:24,
                 from globroots.c:20:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  fail.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from fail.c:22:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  signals.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from signals.c:22:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  signals_byt.c
In file included from caml/config.h:23:0,
                 from signals_byt.c:22:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  printexc.c
In file included from caml/config.h:23:0,
                 from caml/mlvalues.h:22,
                 from caml/backtrace.h:21,
                 from printexc.c:23:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  backtrace_prim.c
In file included from caml/config.h:23:0,
                 from backtrace_prim.c:25:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  backtrace.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from backtrace.c:24:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  compare.c
In file included from caml/config.h:23:0,
                 from caml/mlvalues.h:22,
                 from caml/custom.h:23,
                 from compare.c:20:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  ints.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from ints.c:20:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  floats.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from floats.c:27:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  str.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from str.c:24:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  array.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from array.c:20:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  io.c
In file included from caml/config.h:23:0,
                 from io.c:26:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  extern.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from extern.c:23:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  intern.c
In file included from caml/config.h:23:0,
                 from caml/misc.h:24,
                 from caml/alloc.h:23,
                 from intern.c:24:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  hash.c
In file included from caml/config.h:23:0,
                 from caml/mlvalues.h:22,
                 from hash.c:23:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"

<command-line>:0:0: note: this is the location of the previous definition
gcc -c -O2 -fno-strict-aliasing -fwrapv -Wall -fno-tree-vrp -DOCAML_STDLIB_DIR='L"/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"' -I"/usr/lib/flexdll" -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  sys.c
In file included from caml/config.h:23:0,
                 from sys.c:35:
caml/s.h:2:0: warning: "OCAML_STDLIB_DIR" redefined
 #define OCAML_STDLIB_DIR "/cygdrive/c/ocaml406/ocaml-4.06.1/lib/ocaml"


                                                     ^~~~~~~~
In file included from /usr/include/w32api/winbase.h:24:0,
                 from /usr/include/w32api/windows.h:70,
                 from /usr/include/w32api/rpc.h:16,
                 from /usr/include/w32api/wtypes.h:7,
                 from win32.c:21:
/usr/include/w32api/libloaderapi.h:83:27: note: expected ‘LPSTR {aka char *}’ but argument is of type ‘WCHAR * {aka short unsigned int *}’
   WINBASEAPI DWORD WINAPI GetModuleFileNameA (HMODULE hModule, LPSTR lpFilename, DWORD nSize);
                           ^~~~~~~~~~~~~~~~~~
win32.c:887:33: warning: passing argument 1 of ‘GetFileVersionInfoSizeA’ from incompatible pointer type [-Wincompatible-pointer-types]
   size = GetFileVersionInfoSize(fileName, &dwHandle);
                                 ^~~~~~~~
In file included from /usr/include/w32api/windows.h:75:0,
                 from /usr/include/w32api/rpc.h:16,
                 from /usr/include/w32api/wtypes.h:7,
                 from win32.c:21:
/usr/include/w32api/winver.h:141:16: note: expected ‘LPCSTR {aka const char *}’ but argument is of type ‘WCHAR * {aka short unsigned int *}’
   DWORD WINAPI GetFileVersionInfoSizeA(LPCSTR lptstrFilename,LPDWORD lpdwHandle);
                ^~~~~~~~~~~~~~~~~~~~~~~
win32.c:889:26: warning: passing argument 1 of ‘GetFileVersionInfoA’ from incompatible pointer type [-Wincompatible-pointer-types]
   if (GetFileVersionInfo(fileName, 0, size, versionInfo)) {
                          ^~~~~~~~
In file included from /usr/include/w32api/windows.h:75:0,
                 from /usr/include/w32api/rpc.h:16,
                 from /usr/include/w32api/wtypes.h:7,
                 from win32.c:21:
/usr/include/w32api/winver.h:143:18: note: expected ‘LPCSTR {aka const char *}’ but argument is of type ‘WCHAR * {aka short unsigned int *}’
   WINBOOL WINAPI GetFileVersionInfoA(LPCSTR lptstrFilename,DWORD dwHandle,DWORD dwLen,LPVOID lpData);
                  ^~~~~~~~~~~~~~~~~~~
win32.c:892:32: warning: passing argument 2 of ‘VerQueryValueA’ from incompatible pointer type [-Wincompatible-pointer-types]
     VerQueryValue(versionInfo, L"\\", (void**)&vsfi, &len);
                                ^~~~~
In file included from /usr/include/w32api/windows.h:75:0,
                 from /usr/include/w32api/rpc.h:16,
                 from /usr/include/w32api/wtypes.h:7,
                 from win32.c:21:
/usr/include/w32api/winver.h:147:18: note: expected ‘LPCSTR {aka const char *}’ but argument is of type ‘short unsigned int *’
   WINBOOL WINAPI VerQueryValueA(LPCVOID pBlock,LPCSTR lpSubBlock,LPVOID *lplpBuffer,PUINT puLen);
                  ^~~~~~~~~~~~~~
make[1]: *** [Makefile:205: win32.o] Error 1
make[1]: Leaving directory '/cygdrive/c/ocaml406/ocaml-4.06.1/byterun'
make: *** [Makefile:384: coldstart] Error 2

0 Likes

#6

I remember we used to have a binary distribution on Windows platform for casual users, now it seems to get even more difficult to try ocaml on windows…

0 Likes

#7

I tried the GUI installer provided by fdopen, it failed in the last step. Its version is 4.07 though

0 Likes

#8

The instructions given in my previous reply are for 4.08; for previous versions you need to do:

cp config/m-nt.h byterun/caml/m.h
cp config/s-nt.h byterun/caml/s.h
  1. for microsoft toolchain (cl)

    cp config/Makefile.msvc64 config/Makefile
    
  2. for mingw toolchain (gcc)

    cp config/Makefile.mingw64 config/Makefile
    

and then compile with make world.opt. Note that you need a working development environment for this to work (the compiler needs to be in your path, etc.)

Again all of this is documented in the README.win32.adoc file.

1 Like

#9

This makes a bit further, but now I have such an error:

x86_64-w64-mingw32-gcc -c -O -mms-bitfields -Wall -Wno-unused -fno-tree-vrp -DOCAML_STDLIB_DIR='L"C:/ocamlmgw64/lib"' -I"C:\ocaml406\ocaml-4.06.1\flexdll" -g -DCAML_NAME_SPACE -DUNICODE -D_UNICODE -DWINDOWS_UNICODE=1 prims.c
../boot/ocamlrun ../flexdll/flexlink.exe -chain mingw64 -stack 33554432 -exe -link "-municode" -o ocamlrun.exe prims.o libcamlrun.a -lws2_32 -lversion
** Fatal error: Cannot find file "flexdll_mingw64.o"

0 Likes

#10

You are missing an installed flexlink. The easiest way to get it is to do make flexdll before make world.opt.

NOTE: you will need to completely clean your tree before doing make flexdll (ie git clean -fdx if using a git clone).

0 Likes

#11

try to make flexdll, thanks for the help

Hongbo Zhang@DESKTOP-PCMUAKU /cygdrive/c/ocaml406/ocaml-4.06.1
$ make flexdll
make -C byterun BOOTSTRAPPING_FLEXLINK=yes ocamlrun.exe
make[1]: Entering directory '/cygdrive/c/ocaml406/ocaml-4.06.1/byterun'
x86_64-w64-mingw32-gcc -O -mms-bitfields -Wall -Wno-unused -fno-tree-vrp -DBOOTSTRAPPING_FLEXLINK -DOCAML_STDLIB_DIR='L"C:/ocamlmgw64/lib"' -I"C:\OCaml\bin" -g -municode -o ocamlrun.exe prims.o libcamlrun.a -lws2_32 -lversion
libcamlrun.a(win32.o): In function `caml_dlopen':
/cygdrive/c/ocaml406/ocaml-4.06.1/byterun/win32.c:233: undefined reference to `flexdll_wdlopen'
/cygdrive/c/ocaml406/ocaml-4.06.1/byterun/win32.c:235: undefined reference to `flexdll_dump_exports'
libcamlrun.a(win32.o): In function `caml_dlclose':
/cygdrive/c/ocaml406/ocaml-4.06.1/byterun/win32.c:243: undefined reference to `flexdll_dlclose'
libcamlrun.a(win32.o): In function `caml_dlsym':
/cygdrive/c/ocaml406/ocaml-4.06.1/byterun/win32.c:248: undefined reference to `flexdll_dlsym'
libcamlrun.a(win32.o): In function `caml_globalsym':
/cygdrive/c/ocaml406/ocaml-4.06.1/byterun/win32.c:253: undefined reference to `flexdll_dlopen'
/cygdrive/c/ocaml406/ocaml-4.06.1/byterun/win32.c:253: undefined reference to `flexdll_dlsym'
libcamlrun.a(win32.o): In function `caml_dlerror':
/cygdrive/c/ocaml406/ocaml-4.06.1/byterun/win32.c:258: undefined reference to `flexdll_dlerror'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:181: ocamlrun.exe] Error 1
make[1]: Leaving directory '/cygdrive/c/ocaml406/ocaml-4.06.1/byterun'
make: *** [Makefile:584: flexlink] Error 2

0 Likes

#12

Are you starting from a clean tree? It worked just now for me. I did:

$ curl -L -O https://github.com/ocaml/ocaml/archive/4.06.1.tar.gz
$ cd ocaml-4.06.1
$ cp config/m-nt.h byterun/caml/m.h
$ cp config/s-nt.h byterun/caml/s.h
$ cp config/Makefile.mingw64 config/Makefile
$ git clone https://github.com/alainfrisch/flexdll.git
$ make flexdll world.opt
1 Like

#13

It works now. Thanks!

1 Like

#14

Actually not. I get another error while using the installed ocamlopt.

Hongbo Zhang@DESKTOP-PCMUAKU /cygdrive/c/bucklescript/lib
$ /cygdrive/c/ocamlmgw64/bin/ocamlopt.opt.exe -I 4.06.1 -g -w -a ../jscomp/stubs/ext_basic_hash_stubs.c -w -40-30 -no-alias-deps -I +compiler-libs ocamlcommon.cmxa -o reactjs_jsx_ppx_3.win32 4.06.1/reactjs_jsx_ppx_v3.mli 4.06.1/reactjs_jsx_ppx_v3.ml
** Cannot resolve symbols for C:/ocamlmgw64/lib\libasmrun.a(win32.o):
 flexdll_wdlopen
File "caml_startup", line 1:
Error: Error during linking

0 Likes

#15

Try adding /cygdrive/c/ocamlmgw64/bin to your PATH. Does it solve the issue?

0 Likes

#16

Yes, now it works, thanks a ton!

Another take away is make sure to have OCAMLLIB unset if you have other ocaml installations

1 Like