[wg-windows] mingw, ocamlopt and "input line is too long"

Andre Maroneze Andre.OLIVEIRAMARONEZE at cea.fr
Wed Jul 6 19:45:41 BST 2016

I've been successfully using Andreas Hauptmann's MinGW OPAM repository 
to install somewhat tricky OPAM packages, such as Frama-C, using Cygwin 
and the MinGW-based OCaml provided with it.

However, a constant problem that I have (due to the package itself) is 
Windows' limit of 8k (or 32k, according to the application) characters 
in the command line, which results in the error "input line is too long".

That limit means that, if I compile my package (frama-c) using a short 
path (e.g. C:\Ocaml32\user\frama-c), everything works (thanks to 
Andreas' patches). However, if I try a longer path (at least 60 
characters), there are several calls to "ocamlfind ocamlopt" in my 
Makefile that fail with "input line is too long".

Most of these command lines have less than 6000 characters, which is 
below both limits. Furthermore, I am able to run simple commands such as 
"ocamlfind ocamlopt t1.ml t2.ml t3.ml ...", with up to 32k characters, 
without hitting any limits. But my actual command line is much shorter, 
yet it triggers this error, most certainly due to the flags it uses. 
This makes me think that it may be some internal command executed by 
ocamlfind or ocamlopt that is triggering the limit, e.g. after expanding 
some arguments, but I don't how to get Windows or Cygwin to give me more 
detailed information about this error.

The only hint I've got so far is that the "-shared" flag in my command 
line contributes significantly to the error: I can either trim my 
command to less than 4000 characters while keeping -shared and still 
have the error, or I can keep it over 5000 characters and remove 
"-shared", and the command line parsing error disappears (but then 
ocamlopt does not produce what I need, so this is not a solution).

Has someone else also encountered this problem when compiling on Windows 
with a MinGW-based OCaml? Suggestions on how to avoid it are welcome, 
preferably that do not require modifying the entire compilation process.

(I've tried a few hacks, such as using Python's subprocess module to 
pass the arguments as a list instead of a string, but it didn't work.)

For information, I'm using OCaml 4.02.3+mingw32 on a Windows 8.1.

André Maroneze
Ingénieur-chercheur CEA/LIST
Laboratoire Sûreté et Sécurité des Logiciels

More information about the wg-windows mailing list