3

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

这会产生与此处类似的错误。当我删除-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 中的一个错误;有没有人遇到过类似的情况?我在编译中是否遗漏了任何东西或任何选项?

谢谢。


编辑

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

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

1 回答 1

2

此处无法重现。

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

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

于 2011-12-08T08:52:12.623 回答