关于“topfind”?

时间:2011-11-09 02:19:13

标签: ocaml

当我在顶级手动输入#use "topfind" ;;时,它的工作原理如下:

 #use "topfind" ;;
 - : unit = ()
 Findlib has been successfully loaded. Additional directives:
 #require "package";;      to load a package
 #list;;                   to list the available packages
 #camlp4o;;                to load camlp4 (standard syntax)
 #camlp4r;;                to load camlp4 (revised syntax)
 #predicates "p,q,...";;   to set these predicates
 Topfind.reset();;         to force that packages will be reloaded
 #thread;;                 to enable threads #use "topfind" ;;
  - : unit = ()

但是,当我将#use "topfind";;放入~/.ocamlinit文件时,它不起作用:

>cat ~/.ocamlinit
#use "topfind";;
#require "str";; 
(* #use "money.ml" ;; *)

>ocaml
    Objective Caml version 3.12.0
# #list ;;
Unknown directive `list'.

这似乎是一个奇怪的问题,不是吗?

2 个答案:

答案 0 :(得分:5)

显然ocaml不会加载.ocamlinit。在其中放入一些print_endline进行验证。 一些想法:

  • 您可以使用-init选项明确指定ocamlinit文件。
  • 也许ocaml是你的shell中的一些(错误的)别名?
  • 尝试strace -f -ttT -e open $(which ocaml)查看ocamlinit的搜索位置。

答案 1 :(得分:3)

ygrek

感谢您的快速回答。

  

您可以使用-init选项明确指定ocamlinit文件。

%ocaml -init ~/.ocamlinit有效

  

也许ocaml是shell中的一些(错误的)别名?

没有ocaml别名

  

尝试strace -f -ttT -e open $(哪个ocaml)看看它在哪里寻找ocamlinit

%strace -f -ttT -e open $(which ocaml) 
19:12:28.484440 open("/etc/ld.so.cache", O_RDONLY) = 3 <0.000179>
19:12:28.485002 open("/lib/libm.so.6", O_RDONLY) = 3 <0.000062>
19:12:28.485384 open("/lib/libdl.so.2", O_RDONLY) = 3 <0.000062>
19:12:28.485744 open("/lib/libncursesw.so.5", O_RDONLY) = 3 <0.000061>
19:12:28.486107 open("/lib/libpthread.so.0", O_RDONLY) = 3 <0.000061>
19:12:28.486514 open("/lib/libc.so.6", O_RDONLY) = 3 <0.000060>
19:12:28.488228 open("/usr/bin/ocamlrun", O_RDONLY|O_LARGEFILE) = 3 <0.000018>
19:12:28.488425 open("/usr/bin/ocaml", O_RDONLY|O_LARGEFILE) = 3 <0.000166>
19:12:28.496499 open("/usr/lib/ocaml/ld.conf", O_RDONLY|O_LARGEFILE) = 4 <0.000028>
19:12:28.502249 open("/usr/bin/ocaml", O_RDONLY|O_LARGEFILE) = 3 <0.000021>
19:12:28.506085 open("/usr/lib/ocaml/ld.conf", O_RDONLY|O_LARGEFILE) = 4 <0.000029>
19:12:28.506880 open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3 <0.000020>
Objective Caml version 3.12.1
19:12:28.507797 open("/usr/lib/ocaml/pervasives.cmi", O_RDONLY|O_LARGEFILE) = 3 <0.000019>
19:12:28.511012 open(".ocamlinit", O_RDONLY|O_LARGEFILE) = 3 <0.000018>
19:12:28.511325 open("money.ml", O_RDONLY|O_LARGEFILE) = 4 <0.000020>
19:12:28.513412 open("/usr/lib/ocaml/list.cmi", O_RDONLY|O_LARGEFILE) = 5 <0.000018>
19:12:28.514858 open("/usr/lib/ocaml/printf.cmi", O_RDONLY|O_LARGEFILE) = 5 <0.000020>
19:12:28.527847 open("/usr/lib/ocaml/sys.cmi", O_RDONLY|O_LARGEFILE) = 5 <0.000029>
#

原因是当前目录中有.ocamlinit个文件。因此ocaml使用它代替~/.ocamlinit

谢谢!