OCamlbuild和构建本机动态链接库

时间:2011-12-07 21:09:31

标签: ocaml ocamlbuild

我发布了question on the ocaml listserv没有人回复,我希望有人可以称我为白痴,确认情况或提供创造性解决方案。

通过ocamlbuild构建动态库时,我会陷入最后的链接线,

/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'

这会产生类似于here的错误。删除-cc选项并将-shared标记传递给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将-cc选项传递给所有内容,因此删除它不是一种选择。看起来像是ocamlopt中的一个bug;谁有经历过类似的情况?我 遗漏了编辑中的任何内容或任何选项?

感谢。


修改

我的解决方案是通过myocamlbuild.ml中的标志传递选项

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

1 个答案:

答案 0 :(得分:2)

无法在这里重现。

Ocamlbuild本身并没有传递-cc选项(为什么要这样?)而且我也无法在源代码中找到这样的行为。所以它可能是由你的插件传递的 - 这是错误的,因为ocamlopt在配置时确定了共享库的链接器(通常是gcc -shared),但如果明确指定-cc选项 - 它将愉快地使用它。

NB选项-shared没有“传递”到ocamlopt,而是它启用了链接动态插件,这导致为共享库选择特殊的C链接器(恰好是具有相同命名选项的gcc) 。指定-cc会将其覆盖为整体。

相关问题