如何使用ocamlbuild将-S标志传递给ocamlopt?

Ant*_*ine 6 ocaml ocamlbuild

-S在使用ocamlbuild和corebuild命令构建时,我想将标志传递给ocamlopt.

我知道做ocamlbuild -cflag -S ...不会起作用,因为-Sflag仅存在于ocamlopt而不是ocamlc.

如何使用_tags文件执行此操作?

did*_*erc 4

这是使用myocamlbuild.ml_tags执行此操作的一种方法。

myocamlbuild.ml中,添加一条flag指令,让 ocamlbuild 识别新标签 - 这里是keep_asm - 它将-S在编译为原生时启用选定的文件:

flag ["ocaml";"compile";"native";"keep_asm"] (S [A "-S"]);
Run Code Online (Sandbox Code Playgroud)

如果"native"列表中的字符串没有传递给,则该标志将在使用ocaml 的任何编译flag阶段启用(如字符串和所示),并且会在调用ocamlc时触发,这是您不希望发生的。 "ocaml""compile"

因此,对于仅执行上述操作的完整独立myocamlbuild.ml,结果将如下:

open Ocamlbuild_plugin;;
open Command;;

dispatch begin function
  | Before_rules -> 
    begin
    end
  | After_rules ->
    begin
      flag ["ocaml";"compile";"native";"keep_asm"] (S [ A "-S"]);
    end
  | _ -> ()
end
Run Code Online (Sandbox Code Playgroud)

一旦定义了新标签,您就可以在_tags文件中使用它,就像使用任何其他标签一样,例如:

<myfile.ml>: use_bigarray, keep_asm 
Run Code Online (Sandbox Code Playgroud)