Ocamlopt and the crt2.o file is missing

By installing OCaml on Windows 7, 64-bit (self-tuning), I tried to create a simple exe file with

ocamlopt HelloWorld.ml -o HelloWorld 

As needed, I used the native code compiler (ocamlopt) with Visual C ++ (I have Visual Studio 10 installed) and Microsoft Assembler MASM version 8 (MinGW is also installed); I also set path variables for OCaml (c: \ ProgramFiles \ Ocaml \ bin), MinGW (c: \ ProgramFiles \ MinGW \ bin) and MASM (C: \ masm32 \ bin). However, despite all my efforts and a great search, I can not get around the error message

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

unless I put the HelloWorld.ml file in the lib folder from MinGW where the crt2.o file is located. I understand that the answer may be simple, but I'm stuck. Any help would be greatly appreciated.

+4
source share
4 answers

I assume that mingw needs to somehow find the library files - when it is compiled from source-path to lib, it is hard-coded in binary files, and if not, it will somehow search (environment variables). Try to create either a mingw (or msys) shell that can provide the correct environment, or set the env LIB variable manually. BTW when debugging problems with mingw it will be easier to exclude ocaml first and try to create a simple C program first.

+2
source

I remember that this is a known mistake: contrary to what the documentation says, you also need Cygwin.

Another problem might be 32/64 bit incompatibility, that is, some of your tools use 32-bit targets, while others use 64-bit targets.

+2
source

Could you clarify which OCaml installer you used (URL?). Have you tried installing the installer on this page ? It lists several potential problems and MinGW / MSYS setup for own compilation.

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

+1
source

I wrote the installer.

So, to solve the issue, detailed instructions are at http://protz.github.com/ocaml-installer/ , and you really need to export the correct FLEXLINKFLAGS as an environment variable because ocamlopt uses flexlink (which contains the installer packages). However, flexlink itself does not work out of the box in msys.

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

Greetings

Jonathan

+1
source

Source: https://habr.com/ru/post/1400541/


All Articles