Ocaml 模块案例名称混淆

Ocaml 模块案例名称混淆,ocaml,ocamlbuild,ounit,Ocaml,Ocamlbuild,Ounit,我犯了更新软件的错误,现在我不能运行任何OUnit测试 我想我已经设法将问题归结为一个简单的REPL会话 知道我做错了什么吗 我在一台Mac笔记本电脑上运行它,它有默认的文件系统,但是使用include路径的情况并没有帮助 我更大的问题是: 您的第一个错误可能是因为您的操作系统不区分文件名中的大小写,但OCaml会: $ ocamlobjinfo `ocamlfind query oUnit`/oUnit.cmi File /mnt/home/jun/.opam/system/lib/oUni

我犯了更新软件的错误,现在我不能运行任何OUnit测试

我想我已经设法将问题归结为一个简单的REPL会话

知道我做错了什么吗

我在一台Mac笔记本电脑上运行它,它有默认的文件系统,但是使用include路径的情况并没有帮助


我更大的问题是:


您的第一个错误可能是因为您的操作系统不区分文件名中的大小写,但OCaml会:

$ ocamlobjinfo `ocamlfind query oUnit`/oUnit.cmi
File /mnt/home/jun/.opam/system/lib/oUnit/oUnit.cmi
Unit name: OUnit
Interfaces imported:
    cb146e345f0b34fc8ad4b5afe69d1f20    OUnit
    ...
您可以看到该模块被称为“OUnit”,而不是“OUnit”

第二个错误显然是因为库尚未加载到REPL中。REPL知道函数的存在,但没有加载代码。如果加载库及其所依赖的库,则可以访问该库:

ocaml -I `ocamlfind query oUnit` unix.cma oUnitAdvanced.cma oUnit.cma
        OCaml version 4.01.0

# OUnit.assert_equal;;
- : ?cmp:('a -> 'a -> bool) ->
    ?printer:('a -> string) ->
    ?pp_diff:(Format.formatter -> 'a * 'a -> unit) ->
    ?msg:string -> 'a -> 'a -> unit
= <fun>
ocaml-I`ocamlfind query oUnit`unix.cma oUnitAdvanced.cma oUnit.cma
OCaml版本4.01.0
#主张平等;;
-:?cmp:('a->'a->bool)->
打印机:('a->字符串)->
pp_diff:(Format.formatter->“a*”a->unit)->
?消息:字符串->'a->'a->单位
= 

您的第一个错误可能是因为您的操作系统不区分文件名中的大小写,但OCaml会:

$ ocamlobjinfo `ocamlfind query oUnit`/oUnit.cmi
File /mnt/home/jun/.opam/system/lib/oUnit/oUnit.cmi
Unit name: OUnit
Interfaces imported:
    cb146e345f0b34fc8ad4b5afe69d1f20    OUnit
    ...
您可以看到该模块被称为“OUnit”,而不是“OUnit”

第二个错误显然是因为库尚未加载到REPL中。REPL知道函数的存在,但没有加载代码。如果加载库及其所依赖的库,则可以访问该库:

ocaml -I `ocamlfind query oUnit` unix.cma oUnitAdvanced.cma oUnit.cma
        OCaml version 4.01.0

# OUnit.assert_equal;;
- : ?cmp:('a -> 'a -> bool) ->
    ?printer:('a -> string) ->
    ?pp_diff:(Format.formatter -> 'a * 'a -> unit) ->
    ?msg:string -> 'a -> 'a -> unit
= <fun>
ocaml-I`ocamlfind query oUnit`unix.cma oUnitAdvanced.cma oUnit.cma
OCaml版本4.01.0
#主张平等;;
-:?cmp:('a->'a->bool)->
打印机:('a->字符串)->
pp_diff:(Format.formatter->“a*”a->unit)->
?消息:字符串->'a->'a->单位
= 

我通过将我的
ocamlbuild
调用更改为使用
-use-ocamlfind
解决了这个问题,这似乎解决了所有路径混乱的问题

我还卸载了所有OCaml模块,安装了OPAM,然后通过OPAM安装了OUnit和其他模块,并重新登录,这样我的环境就完美无缺了

现在适用于我的build命令是

这是由我更新的构建脚本生成的

(* Usage: ocaml make.ml [<ModuleToBuild>.{byte,native}] *)

#load "unix.cma";;

let args = match Array.to_list Sys.argv with
  | []      -> failwith "no program on argv"
  | _::[]   -> ["AllTests.byte"]
  | _::argv -> argv

let library_paths = [
  (* TODO: Figure out why `opam install ocamlgraph` fails *)
  "-I"; "/opt/local/lib/ocaml/site-lib/ocamlgraph";
]

(* If the -p flag is first in the argument list, then replace it
   with a host of flags that enable profiling via ocamlprof. *)
let args, c_opt_flags, l_opt_flags =
  match args with
    | "-p"::rest ->
      (* Treat the targets as debug and profile targets. *)
      "-tags"::"debug,profile"
      (* Use profiling versions of the compilers which instrument
         various flow control constructs with entry counters. *)
      ::"-ocamlc"::"ocamlcp"
      ::"-ocamlopt"::"ocamloptp"
      ::rest,
      (* Instrument all available points. *)
      ["-P"; "a"],
      (* Link with a wrapper that dumps profiling data if program
         exits noramlly. *)
      ["-p"]
    | _ -> args, [], []

let standard_flags = [
  "-use-ocamlfind";
  (* TODO: Figure out why `opam install ocamlgraph` fails *)
  "-libs"; "graph";
  "-pkgs"; "str,unix,ounit";  (* TODO: graph *)
  "-cflags"; (String.concat "," (
    [
      "-g";
      "-w"; "+a-4";
      "-warn-error"; "+a-4";
    ]
    @ c_opt_flags
    @ library_paths));
  "-lflags"; (String.concat "," (
    [
      "-g";
    ]
    @ l_opt_flags
    @ library_paths));
]

let build_command = "ocamlbuild"

let argv = build_command::(standard_flags @ args)

let _ = begin
  Printf.printf "%s\n" (String.concat " \\\n\t" argv);
  flush stdout;
  Unix.execvp build_command (Array.of_list argv);
end;;
(*用法:ocaml make.ml[.{byte,native}]*)
#加载“unix.cma”;;
让args=将Array.to_list Sys.argv与匹配
|[]->故障,且“argv上无程序”
|\:[]->[“AllTests.byte”]
|\:argv->argv
让库_路径=[
(*TODO:找出“opam安装ocamlgraph”失败的原因*)
“-I”;“/opt/local/lib/ocaml/site lib/ocamlgraph”;
]
(*如果参数列表中的第一个是-p标志,则替换它
带有大量标志,可通过ocamlprof.*启用分析功能)
设args、c_opt_标志、l_opt_标志=
将args与
|“-p”::剩余->
(*将目标视为调试和配置文件目标。*)
-标记“:“调试,配置文件”
(*使用哪种仪器的编译器的分析版本
具有入口计数器的各种流控制构造。*)
:“-ocamlc”:“ocamlcp”
:“-ocamlopt”:“ocamloptp”
::休息,
(*测量所有可用点。*)
[“-P”;“a”],
(*链接到一个包装器,该包装器在程序运行时转储分析数据
退出Noramly。*)
[“-p”]
|->args,[],[]
让标准_标志=[
“-使用ocamlfind”;
(*TODO:找出“opam安装ocamlgraph”失败的原因*)
“-libs”;“图形”;
“-pkgs”;“str,unix,ounit”;(*TODO:graph*)
“-cflags”;(String.concat“,”(
[
“-g”;
“-w”;“+a-4”;
“-警告错误”;“+a-4”;
]
@c_opt_标志
@图书馆),;
“-lflags”;(String.concat“,”(
[
“-g”;
]
@l_opt_标志
@图书馆),;
]
让build\u命令=“ocamlbuild”
让argv=build_命令::(标准_标志@args)
让我们开始吧
Printf.Printf“%s\n”(String.concat“\\\n\t”argv);
冲洗冲洗液;
Unix.execvp build_命令(Array.of_list argv);
终止

我通过将我的
ocamlbuild
调用更改为使用
-use-ocamlfind
解决了这个问题,这似乎解决了所有路径混乱的问题

我还卸载了所有OCaml模块,安装了OPAM,然后通过OPAM安装了OUnit和其他模块,并重新登录,这样我的环境就完美无缺了

现在适用于我的build命令是

这是由我更新的构建脚本生成的

(* Usage: ocaml make.ml [<ModuleToBuild>.{byte,native}] *)

#load "unix.cma";;

let args = match Array.to_list Sys.argv with
  | []      -> failwith "no program on argv"
  | _::[]   -> ["AllTests.byte"]
  | _::argv -> argv

let library_paths = [
  (* TODO: Figure out why `opam install ocamlgraph` fails *)
  "-I"; "/opt/local/lib/ocaml/site-lib/ocamlgraph";
]

(* If the -p flag is first in the argument list, then replace it
   with a host of flags that enable profiling via ocamlprof. *)
let args, c_opt_flags, l_opt_flags =
  match args with
    | "-p"::rest ->
      (* Treat the targets as debug and profile targets. *)
      "-tags"::"debug,profile"
      (* Use profiling versions of the compilers which instrument
         various flow control constructs with entry counters. *)
      ::"-ocamlc"::"ocamlcp"
      ::"-ocamlopt"::"ocamloptp"
      ::rest,
      (* Instrument all available points. *)
      ["-P"; "a"],
      (* Link with a wrapper that dumps profiling data if program
         exits noramlly. *)
      ["-p"]
    | _ -> args, [], []

let standard_flags = [
  "-use-ocamlfind";
  (* TODO: Figure out why `opam install ocamlgraph` fails *)
  "-libs"; "graph";
  "-pkgs"; "str,unix,ounit";  (* TODO: graph *)
  "-cflags"; (String.concat "," (
    [
      "-g";
      "-w"; "+a-4";
      "-warn-error"; "+a-4";
    ]
    @ c_opt_flags
    @ library_paths));
  "-lflags"; (String.concat "," (
    [
      "-g";
    ]
    @ l_opt_flags
    @ library_paths));
]

let build_command = "ocamlbuild"

let argv = build_command::(standard_flags @ args)

let _ = begin
  Printf.printf "%s\n" (String.concat " \\\n\t" argv);
  flush stdout;
  Unix.execvp build_command (Array.of_list argv);
end;;
(*用法:ocaml make.ml[.{byte,native}]*)
#加载“unix.cma”;;
让args=将Array.to_list Sys.argv与匹配
|[]->故障,且“argv上无程序”
|\:[]->[“AllTests.byte”]
|\:argv->argv
让库_路径=[
(*TODO:找出“opam安装ocamlgraph”失败的原因*)
“-I”;“/opt/local/lib/ocaml/site lib/ocamlgraph”;
]
(*如果参数列表中的第一个是-p标志,则替换它
带有大量标志,可通过ocamlprof.*启用分析功能)
设args、c_opt_标志、l_opt_标志=
将args与
|“-p”::剩余->
(*将目标视为调试和配置文件目标。*)
-标记“:“调试,配置文件”
(*使用哪种仪器的编译器的分析版本
具有入口计数器的各种流控制构造。*)
:“-ocamlc”:“ocamlcp”
:“-ocamlopt”:“ocamloptp”
::休息,
(*测量所有可用点。*)
[“-P”;“a”],
(*链接到一个包装器,该包装器在程序运行时转储分析数据
退出Noramly。*)
[“-p”]
|->args,[],[]
让标准_标志=[
“-使用ocamlfind”;
(*TODO:找出“opam安装ocamlgraph”失败的原因*)
“-libs”;“图形”;
“-pkgs”;“str,unix,ounit”;(*TODO:graph*)
“-cflags”;(String.concat“,”(
[
“-g”;
“-w”;“+a-4”;
“-警告错误”;“+a-4”;
]
@c_opt_标志
@图书馆),;
“-lflags”;(String.concat“,”(
[
“-g”;
]
@l_opt_标志
@图书馆),;
]
让build\u命令=“ocamlbuild”
让argv=build_命令::(标准_标志@args)
让我们开始吧
Printf.Printf“%s\n”(String.concat“\\\n\t”argv);
flus