ocamlrootsudoopamocamlfind

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


I have an issue here, that really drives me nuts. I never worked with OCaml, do not know anything about it or how it works.

The problem: i need to install camlidl library. I did it through opam (opam install camlidl).

As i said before, i have no idea about OCaml. ocamlfind list, did not show a package list . Searched the net - found out that running eval $'opam config eval' helps.

strangely (i do not know why) ocamlfind was able to see the package after this command execution, BUT(!) if i run sudo ocamlfind list it will show the list without this package.

Can anyone help me understand why is this happening and how to fix this? I need to compile something that requires camlidl, and it has to be done under sudo.

Thank You in advance!

Execution of 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])

Execution of 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])

Execution of 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

Execution for 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

Solution

  • eval $(opam config env) populates your environment with variables, that helps ocamlfind to find libraries, c.f., PIP's virtual environment in Python.

    When you're evaluating this command under the user account, you populate environment only for a user, so that it is not visible for other users including root. Moreover, usually, you install ocaml packages in a user-local mode, not system wide.

    To solve your problem, without delving deep into OCaml infrastructure I would suggest the following,

    1. If it is possible, do not use sudo. Actually, I do not see the reason to use sudo for the compilation. It maybe needed only for the installation. So, use make and sudo make install. If you already, accidentally run make with sudo it may create files under root ownership, so you need to remove everything and start from scratch.

    2. If it is not possible (the package build system is so broken), then try to install opam under the root user, and do everything as a root, e.g., switch to a root mode with sudo su - and continue as normal.