开发者

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

开发者 https://www.devze.com 2023-02-01 10:58 出处:网络
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 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?


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).


I don't know ocaml, but it looks like you have to use flexlink. The missing definitions are in the .o files in /usr/lib/flexdll/, and there's a special linker called /bin/flexlink.

http://alain.frisch.fr/flexdll.html advocates this:
flexlink -chain cygwin -exe -o dump.exe dump.o

linux resolves missing symbols at run-time, so linux is no good measurement.

0

精彩评论

暂无评论...
验证码 换一张
取 消