3
votes

I posted a question on the ocaml listserv that nobody responded to, I'm hoping someone here can either call me an idiot, confirm the situation, or offer up a creative solution.

When building a dynamic library through ocamlbuild I get stuck on the final linking line,

/opt/ocaml-3.12.1/bin/ocamlopt.opt -shared -verbose -cc gcc plugins/example.cmx -o plugins/example.cmxs -ccopt -v
+ as -o 'plugins/example.cmxs.startup.o' '/tmp/camlstartupe6993f.s'
+ gcc -o 'plugins/example.cmxs'   '-L/opt/ocaml-3.12.1/lib/ocaml' -v 'plugins/example.cmxs.startup.o' 'plugins/example.o'

This creates an error similar to here. This error is fixed when I remove the -cc option and the -shared flag gets passed to gcc.

/opt/ocaml-3.12.1/bin/ocamlopt.opt -shared -verbose plugins/example.cmx -o plugins/example.cmxs -ccopt -v
+ as -o 'plugins/example.cmxs.startup.o' '/tmp/camlstartup2c31a2.s'
+ gcc -shared -o 'plugins/example.cmxs'   '-L/opt/ocaml-3.12.1/lib/ocaml' -v 'plugins/example.cmxs.startup.o' 'plugins/example.o'

OCamlbuild passes the -cc option to everything, so removing that isn't an option. Seems like a bug in ocamlopt; has anyone experienced similar situations? Am I missing anything or any options in compilation?

Thanks.


EDIT

My solution is just to pass the options via a flag in myocamlbuild.ml

flag ["shared"; "link"]
    (S [A"-ccopt";A"-shared"]);
1

1 Answers

2
votes

Cannot reproduce here.

Ocamlbuild by itself doesn't pass the -cc option (why should it?) and I cannot find such behaviour in sources either. So it is probably passed by your plugin - and it is wrong, because ocamlopt determines the linker for shared libraries at configure time (usually it is gcc -shared), but if -cc option is specified explicitely - it will happily use that instead.

NB option -shared is not "passed" to ocamlopt, but instead it enables linking a dynamic plugin and this results in selecting special C linker for shared libraries (which happens to be gcc with the same-named option). Specifying -cc overrides it as a whole.