首页 > 解决方案 > 在 utop 中使用随 opam 安装的软件包

问题描述

我用 opam 安装了 yojson:

opam install yojson

我想在 utop 中使用它,但我无法让它工作。我已经在 utop 中尝试了这些命令,但都没有工作(它抱怨找不到文件/包):

#use "Yojson";;
#use "yojson";;
#require "Yojson";;
#require "yojson";;

在 utop 中使用 opam 包时我应该注意什么其他配置?

标签: ocamlopamutop

解决方案


正确的调用是(包括#字符):

#use "topfind";;
#require "yojson";;

第一个命令启用#require指令(它不是标准指令,而是来自工具),如果它还没有,最好ocamlfind将它添加到您的文件中。~/.ocamlinit第二个指令实际上加载了yojson库。您还可以使用该#list指令列出所有可用的包,以及ocamlfind list同一 puprose 的 shell 命令。


推荐阅读