0

有人可以帮我设置 OCaml 项目吗?

我想使用沙丘创建一个构建环境,因为我正在开发一个 gui 应用程序,所以我想从这里构建 lablgtk 示例:GTK Hello World! 我可以使用链接中的说明来构建它,但我想使用沙丘来构建它,这目前不起作用。我收到一个 cmi 文件丢失的错误。

命令行界面中的输出:

File "main.ml", line 10, characters 2-44:
10 |   window#connect#destroy ~callback:Main.quit;
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type GtkSignal.id
       but an expression was expected of type unit
       because it is in the left-hand side of a sequence

来自 VScode 中 Merlin 的 Infro

This expression has type GtkSignal.id but an expression was expected of type
  unit
because it is in the left-hand side of a sequence
GtkSignal.id is abstract because no corresponding cmi file was found in path.merlin

输出与dune build main.exe --verbose

Workspace root: /home/patrick/git/hello
Running[0]: /usr/bin/nproc > /tmp/duneaf7943.output 2> /dev/null
Auto-detected concurrency: 4
disable binary cache
Running[1]: /usr/bin/ocamlc.opt -config > /tmp/dune2611b5.output
Dune context:
 { name = "default"
 ; kind = "default"
 ; profile = Dyn
 ; merlin = true
 ; for_host = None
 ; fdo_target_exe = None
 ; build_dir = "default"
 ; toplevel_path = Some External "/home/patrick/.opam/default/lib/toplevel"
 ; ocaml_bin = External "/usr/bin"
 ; ocaml = Ok External "/home/patrick/.opam/default/bin/ocaml"
 ; ocamlc = External "/usr/bin/ocamlc.opt"
 ; ocamlopt = Ok External "/usr/bin/ocamlopt.opt"
 ; ocamldep = Ok External "/usr/bin/ocamldep.opt"
 ; ocamlmklib = Ok External "/usr/bin/ocamlmklib.opt"
 ; env =
     map
       { "INSIDE_DUNE" : "/home/patrick/git/hello/_build/default"
       ; "OCAMLFIND_IGNORE_DUPS_IN" :
           "/home/patrick/git/hello/_build/install/default/lib"
       ; "OCAMLPATH" :
           "/home/patrick/git/hello/_build/install/default/lib"
       ; "OCAMLTOP_INCLUDE_PATH" :
           "/home/patrick/git/hello/_build/install/default/lib/toplevel"
       ; "OCAML_COLOR" : "always"
       ; "OPAMCOLOR" : "always"
       }
 ; findlib_path = [ External "/home/patrick/.opam/default/lib" ]
 ; arch_sixtyfour = true
 ; natdynlink_supported = true
 ; supports_shared_libraries = true
 ; ocaml_config =
     { version = "4.10.0"
     ; standard_library_default = "/usr/lib/ocaml"
     ; standard_library = "/usr/lib/ocaml"
     ; standard_runtime = "the_standard_runtime_variable_was_deleted"
     ; ccomp_type = "cc"
     ; c_compiler = "gcc"
     ; ocamlc_cflags = [ "-O2"; "-fno-strict-aliasing"; "-fwrapv"; "-fPIC" ]
     ; ocamlopt_cflags = [ "-O2"; "-fno-strict-aliasing"; "-fwrapv" ]
     ; bytecomp_c_compiler =
         [ "gcc"
         ; "-O2"
         ; "-fno-strict-aliasing"
         ; "-fwrapv"
         ; "-fPIC"
         ; "-D_FILE_OFFSET_BITS=64"
         ; "-D_REENTRANT"
         ]
     ; bytecomp_c_libraries = [ "-lm"; "-ldl"; "-lpthread" ]
     ; native_c_compiler =
         [ "gcc"
         ; "-O2"
         ; "-fno-strict-aliasing"
         ; "-fwrapv"
         ; "-D_FILE_OFFSET_BITS=64"
         ; "-D_REENTRANT"
         ]
     ; native_c_libraries = [ "-lm"; "-ldl" ]
     ; cc_profile = []
     ; architecture = "amd64"
     ; model = "default"
     ; int_size = 63
     ; word_size = 64
     ; system = "linux"
     ; asm = [ "as" ]
     ; asm_cfi_supported = true
     ; with_frame_pointers = false
     ; ext_exe = ""
     ; ext_obj = ".o"
     ; ext_asm = ".s"
     ; ext_lib = ".a"
     ; ext_dll = ".so"
     ; os_type = "Unix"
     ; default_executable_name = "a.out"
     ; systhread_supported = true
     ; host = "x86_64-pc-linux-gnu"
     ; target = "x86_64-pc-linux-gnu"
     ; profiling = false
     ; flambda = false
     ; spacetime = false
     ; safe_string = false
     ; exec_magic_number = "Caml1999X027"
     ; cmi_magic_number = "Caml1999I027"
     ; cmo_magic_number = "Caml1999O027"
     ; cma_magic_number = "Caml1999A027"
     ; cmx_magic_number = "Caml1999Y027"
     ; cmxa_magic_number = "Caml1999Z027"
     ; ast_impl_magic_number = "Caml1999M027"
     ; ast_intf_magic_number = "Caml1999N027"
     ; cmxs_magic_number = "Caml1999D027"
     ; cmt_magic_number = "Caml1999T027"
     ; natdynlink_supported = true
     ; supports_shared_libraries = true
     ; windows_unicode = false
     }
 }
Actual targets:
- _build/default/main.exe
Running[2]: (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I .main.eobjs/byte -I /home/patrick/.opam/default/lib/lablgtk2 -I /usr/lib/ocaml/threads -no-alias-deps -opaque -o .main.eobjs/byte/dune__exe__Main.cmo -c -impl main.ml)
Command [2] exited with code 2:
$ (cd _build/default && /usr/bin/ocamlc.opt -w @1..3@5..28@30..39@43@46..47@49..57@61..62-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I .main.eobjs/byte -I /home/patrick/.opam/default/lib/lablgtk2 -I /usr/lib/ocaml/threads -no-alias-deps -opaque -o .main.eobjs/byte/dune__exe__Main.cmo -c -impl main.ml)
File "main.ml", line 10, characters 2-44:
10 |   window#connect#destroy ~callback:Main.quit;
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type GtkSignal.id
       but an expression was expected of type unit
       because it is in the left-hand side of a sequence
4

1 回答 1

0

警告是正确的(示例代码风格不好)。不同之处在于,dune 默认认为这是一个致命错误(在进行开发构建时),而其他构建系统可能认为它只是一个警告,或者根本不显示它(参见 参考资料ocamlc -strict-sequence)。

要修复它,您可以定义一个辅助运算符,如下所示:

(* Connect a signal handler, ignoring the resulting signal ID.
   This avoids having to use [|> ignore] everywhere. *)
let (==>) (signal:(callback:_ -> GtkSignal.id)) callback =
  ignore (signal ~callback)

然后替换例如

window#connect#destroy ~callback:Main.quit;

window#connect#destroy ==> Main.quit;

你也得修factory#add_item。例如:

let _ : GMenu.menu_item = factory#add_item "Quit" ~key:_Q ~callback:Main.quit in
于 2020-08-04T14:03:42.163 回答