Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ocaml + LLVM under cygwin (or, more generally, statically linking with C object files under cygwin)?

The tests for the Ocaml bindings (which are automatically installed if you make LLVM with Ocaml already installed) all fail under cygwin, and when I try to create even the most trivial program, I get the same error that all of the built-in tests fail on:

> ocamlopt -I +llvm-2.8 -cc g++ llvm.cmxa llvm_bitwriter.cmxa llvm_trivial.ml -o llvm_trivial
/usr/lib/ocaml/libasmrun.a(unix.o):unix.c:(.text+0x14a): undefined reference to `_flexdll_dlerror'
/usr/lib/ocaml/libasmrun.a(unix.o):unix.c:(.text+0x177): undefined reference to `_flexdll_dlopen'
/usr/lib/ocaml/libasmrun.a(unix.o):unix.c:(.text+0x193): undefined reference to `_flexdll_dlopen'
/usr/lib/ocaml/libasmrun.a(unix.o):unix.c:(.text+0x1a2): undefined reference to `_flexdll_dlsym'
/usr/lib/ocaml/libasmrun.a(unix.o):unix.c:(.text+0x1bc): undefined reference to `_flexdll_dlsym'
/usr/lib/ocaml/libasmrun.a(unix.o):unix.c:(.text+0x1cf): undefined reference to `_flexdll_dlclose'
collect2: ld returned 1 exit status
File "caml_startup", line 1, characters 0-1:
Error: Error during linking

Googling around indicates that this isn't LLVM specific, and that other people have the same problem, but I couldn't find a solution. I have flexdll installed. Am I just not referencing it correctly?

This works for me on my linux system, so I think it's something particular to what I'm doing on cygwin. Any suggestions?

like image 233
dan Avatar asked Dec 26 '10 20:12

dan


1 Answers

flexlink is invoked by ocamlopt during linking, run with -verbose option to see how it gets called and what is missing. -cc g++ option looks especially suspicious cause it probably drops flexlink and uses g++ as a linker instead, which of course cannot find flexdll symbols (referenced from ocaml code generated by flexlink-aware ocamlopt).

like image 119
ygrek Avatar answered Nov 02 '22 23:11

ygrek