命令 "sudo ocamlfind list" 和 "ocamlfind list" 的不同结果

different results for commands "sudo ocamlfind list" and "ocamlfind list"

我有一个问题,这真的让我抓狂。 我从未使用过 OCaml,对它或它的工作原理一无所知。

问题:我需要安装 camlidl 库。我是通过 opam (opam install camlidl) 做到的。

正如我之前所说,我对 OCaml 一无所知。 ocamlfind list,没有显示包列表。搜索网络 - 发现 运行ning eval $'opam config eval' 有帮助。

奇怪的是(我不知道为什么)ocamlfind 在这个命令执行后能够看到包,但是(!)如果我 运行 sudo ocamlfind list 它会显示没有这个包的列表。

谁能帮我理解为什么会这样以及如何解决这个问题? 我需要编译一些需要camlidl的东西,而且必须在sudo下完成。

提前致谢!

执行ocamlfind list

bigarray            (version: [distributed with Ocaml])
bytes               (version: [OCaml strictly before 4.02])
camlidl             (version: 1.05)
camlp4              (version: [distributed with Ocaml])
camlp4.exceptiontracer (version: [distributed with Ocaml])
camlp4.extend       (version: [distributed with Ocaml])
camlp4.foldgenerator (version: [distributed with Ocaml])
camlp4.fulllib      (version: [distributed with Ocaml])
camlp4.gramlib      (version: [distributed with Ocaml])
camlp4.lib          (version: [distributed with Ocaml])
camlp4.listcomprehension (version: [distributed with Ocaml])
camlp4.locationstripper (version: [distributed with Ocaml])
camlp4.macro        (version: [distributed with Ocaml])
camlp4.mapgenerator (version: [distributed with Ocaml])
camlp4.metagenerator (version: [distributed with Ocaml])
camlp4.profiler     (version: [distributed with Ocaml])
camlp4.quotations   (version: [distributed with Ocaml])
camlp4.quotations.o (version: [distributed with Ocaml])
camlp4.quotations.r (version: [distributed with Ocaml])
camlp4.tracer       (version: [distributed with Ocaml])
compiler-libs       (version: [distributed with Ocaml])
compiler-libs.bytecomp (version: [distributed with Ocaml])
compiler-libs.common (version: [distributed with Ocaml])
compiler-libs.optcomp (version: [distributed with Ocaml])
compiler-libs.toplevel (version: [distributed with Ocaml])
dynlink             (version: [distributed with Ocaml])
findlib             (version: 1.5.5)
graphics            (version: [distributed with Ocaml])
labltk              (version: [distributed with Ocaml])
num                 (version: [distributed with Ocaml])
num-top             (version: 1.5.5)
num.core            (version: [internal])
oUnit               (version: 2.0.0)
oUnit.advanced      (version: 2.0.0)
oUnit.threads       (version: 2.0.0)
ocamlbuild          (version: [distributed with Ocaml])
ocamlgraph          (version: 1.8.6)
stdlib              (version: [distributed with Ocaml])
str                 (version: [distributed with Ocaml])
threads             (version: [distributed with Ocaml])
threads.posix       (version: [internal])
threads.vm          (version: [internal])
unix                (version: [distributed with Ocaml])

执行sudo ocamlfind list

bigarray            (version: [distributed with Ocaml])
camlp4              (version: [distributed with Ocaml])
camlp4.exceptiontracer (version: [distributed with Ocaml])
camlp4.extend       (version: [distributed with Ocaml])
camlp4.foldgenerator (version: [distributed with Ocaml])
camlp4.fulllib      (version: [distributed with Ocaml])
camlp4.gramlib      (version: [distributed with Ocaml])
camlp4.lib          (version: [distributed with Ocaml])
camlp4.listcomprehension (version: [distributed with Ocaml])
camlp4.locationstripper (version: [distributed with Ocaml])
camlp4.macro        (version: [distributed with Ocaml])
camlp4.mapgenerator (version: [distributed with Ocaml])
camlp4.metagenerator (version: [distributed with Ocaml])
camlp4.profiler     (version: [distributed with Ocaml])
camlp4.quotations   (version: [distributed with Ocaml])
camlp4.quotations.o (version: [distributed with Ocaml])
camlp4.quotations.r (version: [distributed with Ocaml])
camlp4.tracer       (version: [distributed with Ocaml])
compiler-libs       (version: [distributed with Ocaml])
compiler-libs.bytecomp (version: [distributed with Ocaml])
compiler-libs.common (version: [distributed with Ocaml])
compiler-libs.optcomp (version: [distributed with Ocaml])
compiler-libs.toplevel (version: [distributed with Ocaml])
dynlink             (version: [distributed with Ocaml])
findlib             (version: 1.4.1)
graphics            (version: [distributed with Ocaml])
labltk              (version: [distributed with Ocaml])
num                 (version: [distributed with Ocaml])
num-top             (version: 1.4.1)
num.core            (version: [internal])
oUnit               (version: 2.0.0)
oUnit.advanced      (version: 2.0.0)
oUnit.threads       (version: 2.0.0)
ocamlbuild          (version: [distributed with Ocaml])
ocamlgraph          (version: 1.8.5)
stdlib              (version: [distributed with Ocaml])
str                 (version: [distributed with Ocaml])
threads             (version: [distributed with Ocaml])
threads.posix       (version: [internal])
threads.vm          (version: [internal])
unix                (version: [distributed with Ocaml])

执行opam

Installed packages for system:
base-bigarray   base  Bigarray library distributed with the OCaml compiler
base-threads    base  Threads library distributed with the OCaml compiler
base-unix       base  Unix library distributed with the OCaml compiler
camlidl         1.05  Stub code generator for OCaml
ocamlfind      1.5.5  A library manager for OCaml
ocamlgraph     1.8.6  A generic graph library for OCaml
ounit          2.0.0  Unit testing framework loosely based on HUnit. It is similar to JUnit, and other XUnit testing frameworks

执行 sudo -i opam list

Installed packages for system:
base-bigarray   base  Bigarray library distributed with the OCaml compiler
base-threads    base  Threads library distributed with the OCaml compiler
base-unix       base  Unix library distributed with the OCaml compiler
camlidl         1.05  Stub code generator for OCaml

eval $(opam config env) 用变量填充您的环境,这有助于 ocamlfind 查找库,c.f,PIP 在 Python 中的虚拟环境。

当您在用户帐户下评估此命令时,您仅为一个用户填充环境,因此其他用户(包括 root)看不到它。此外,通常,您在用户本地模式下安装 ocaml 包,而不是在系统范围内。

为了解决您的问题,无需深入研究 OCaml 基础结构,我会提出以下建议,

  1. 如果可以,请不要使用sudo。实际上,我没有看到使用 sudo 进行编译的原因。它可能只需要安装。所以,使用 makesudo make install。如果您已经不小心 运行 makesudo 它可能会在 root 所有权下创建文件,因此您需要删除所有内容并从头开始。

  2. 如果不可能(包构建系统如此糟糕),则尝试在 root 用户下安装 opam,并以 root 身份执行所有操作,例如,切换到 root 模式sudo su - 并照常继续。