首页 > 解决方案 > 当我要求使用 ocamlopt 时,为什么沙丘使用 ocamlc?

问题描述

$ dune build ./src/main.exe --profile=release
      ocamlc src/.main.eobjs/byte/ast.{cmi,cmo,cmt} (exit 2)
(cd _build/default && /usr/bin/ocamlc.opt -w -40 -O3 -g -bin-annot -I src/.main.eobjs/byte -I /home/jackprograms/.opam/default/lib/cairo2 -I /home/jackprograms/.opam/default/lib/lablgtk3 -I /usr/lib/ocaml/threads -no-alias-deps -o src/.main.eobjs/byte/ast.cmo -c -impl src/ast.ml)
/usr/bin/ocamlc.opt: unknown option '-O3'.

我跑了这个,沙丘正在使用 ocamlc 字节码......我正在使用exe这意味着本机,正如我在沙丘文档中看到的那样。为什么它应该运行 ocamlopt 却运行 ocamlc?

(executable
 (name main)
 (libraries lablgtk3)
 (modes exe))

(ocamllex
 (modules lexer))

(ocamlyacc
 (modules parser))

(env
 (dev
  (flags (:standard -w +42)))
 (release
  (flags (:standard -O3))))

^ 在src目录中

标签: ocamlocaml-dune

解决方案


它仍将ocamlc用于编译.cmi文件。

而不是使用flags(例如(flags (:standard -O3))),使用ocamlopt_flags

(executable
 (name main)
 (libraries lablgtk3)
 (modes exe))

(ocamllex
 (modules lexer))

(ocamlyacc
 (modules parser))

(env
 (dev
  (flags (:standard -w +42)))
 (release
  (ocamlopt_flags (:standard -O3))))

推荐阅读