4

Having installed OCaml on Windows 7, 64 bit (self-installer), I tried to create a simple exe file with

ocamlopt HelloWorld.ml -o HelloWorld

As required I used the native-code compiler (ocamlopt) with Visual C++ (I have Visual Studio 10 installed) and the Microsoft Assembler MASM version 8 (MinGW is also installed); I have also set the path variables for OCaml (c:\ProgramFiles\Ocaml\bin), MinGW (c:\ProgramFiles\MinGW\bin) and MASM (C:\masm32\bin). However, despite my best efforts and much searching I cannot get around the error message

**Fatal error, Cannot find file "crt2.o"
File "caml_startup", line 1, characters 0-1:
Error: error during linking.

except when I place the HelloWorld.ml file in the lib folder of MinGW, where the crt2.o file is located. I appreciate the answer may be straightforward, but I am stuck. Any help would be greatly appreciated.

user1060986
  • 141
  • 1
  • 1
  • 3
  • 1
    I recall having to set the global flags for flexlink (`FLEXLINKFLAGS`) to get everything passed their properly. Set all the verbose levels as you can, like `-cclib --verbose -ccopt -v` to see the external commands being run. Very helpful. – nlucaroni Mar 09 '12 at 16:35

4 Answers4

2

I guess mingw needs some way to find library files - when it is compiled from source - path to lib is hardcoded in binaries, if not - it will search in some way (environment variables). Try building either from mingw (or msys) shell which is likely to provide correct environment or set the LIB env variable manually. BTW when debugging mingw problems it will be easier to rule out ocaml first and try building simple C program first.

ygrek
  • 6,656
  • 22
  • 29
  • I tried using the MinGW shell, as you suggested, and was able to build it that way, using the standard command - no linking problems at all. Will now look into all the other options suggested here to see if I can get it working via the Windows shell. Many thanks – user1060986 Mar 10 '12 at 04:52
2

I kind of remember it is a known bug: contrary to what is said in the documentation, you also need Cygwin installed.

Another problem might be a 32/64 bit incompatibility, i.e. some of your tools are using 32 bits targets, while other ones use 64 bits targets.

Fabrice Le Fessant
  • 4,222
  • 23
  • 36
1

I wrote the installer.

So just to settle the matter, the detailed instructions are at http://protz.github.com/ocaml-installer/ and indeed you have to export the right FLEXLINKFLAGS as an environment variable because ocamlopt uses flexlink (which the installer packages). However, flexlink itself doesn't work out of the box in a msys environment.

The next version of the installer will encourage you to use cygwin, where everything should work flawlessly.

Cheers,

jonathan

Jonathan Protzenko
  • 1,709
  • 8
  • 13
1

Could you be more precise on which OCaml installer you used (URL?). Have you tried the installer present on this page? It lists several potential issues and how to setup MinGW/MSYS for native compilation.

It is very important that we understand clearly the problem you have and, eventually, the solution you found, so that we can tell the maintainers how to update the relevant documentation.

gasche
  • 31,259
  • 3
  • 78
  • 100