Hi ! We are trying to embed some ocaml into a rust application, and we naturally dived into OCaml - Interfacing C with OCaml, especially how -output-obj
works.
To compile pure ocaml code, we are using the -cc
flag to specify our compiler / linker, which might be different from the one available in the current $PATH
. We would like to have the same control when using -output-obj
but it seems that in this mode, ocaml uses a non mutable value set by ./configure
(in general, it would be ld -r -o
). Here is what I tried:
$ # Simple example to see ocaml using the `ld` script we provide.
$ ocamlopt.opt -verbose -cc $PWD/myld.sh foo.ml
+ as -o 'foo.o' '/tmp/camlasm4a491f.s'
+ as -o '/tmp/camlstartupe1d65d.o' '/tmp/camlstartup09af64.s'
+ /tmp/vsiles/myld.sh -o 'a.out' '-L/home/vsiles/opam/4.14.0+options/lib/ocaml' '/tmp/camlstartupe1d65d.o' '/home/vsiles/opam/4.14.0+options/lib/ocaml/std_exit.o' 'foo.o' '/home/vsiles/opam/4.14.0+options/lib/ocaml/stdlib.a' '/home/vsiles/opam/4.14.0+options/lib/ocaml/libasmrun.a' -lm -ldl
$ # regular call with -output-obj, we see `ld -r -o`
$ ocamlopt.opt -verbose -output-obj foo.ml -o my-foo.o
+ as -o 'foo.o' '/tmp/camlasm8f4d5c.s'
+ as -o '/tmp/camlstartup91a768.o' '/tmp/camlstartupaa17f6.s'
+ ld -r -o 'my-foo.o' '-L/home/vsiles/opam/4.14.0+options/lib/ocaml' '/tmp/camlstartup91a768.o' 'foo.o' '/home/vsiles/opam/4.14.0+options/lib/ocaml/stdlib.a'
$ # attempting to use a different ld, it's ignored
$ ocamlopt.opt -verbose -output-obj foo.ml -o my-foo.o -cc $PWD/myld.sh
+ as -o 'foo.o' '/tmp/camlasme90ae0.s'
+ as -o '/tmp/camlstartupef2505.o' '/tmp/camlstartup3ad298.s'
+ ld -r -o 'my-foo.o' '-L/home/vsiles/opam/4.14.0+options/lib/ocaml' '/tmp/camlstartupef2505.o' 'foo.o' '/home/vsiles/opam/4.14.0+options/lib/ocaml/stdlib.a'
So I guess my question are:
- is this some already known limitation ? I tried to looked for it but didn’t find much
- would ocaml benefit from a way to configure the
ld
used with-output-obj
? I can try a PR to add this, but if there’s valid reasons no to do so, I’d love to hear more