Using ocamlfind with local directories

537 Views Asked by At

Since I don't have root access on a workstation, I installed oUnit locally, into ~/ounit. I can load the module in the interpreter if I run

ocaml -I ~/ounit/oUnit

Now I'd like to run the test, so I try to compile it:

ocamlfind ocamlc -o test -package oUnit -I ~/ounit/oUnit -linkpkg -g foo.ml test.ml

Unfortunately, ocamlfind doesn't detect the oUnit package

ocamlfind: Package `oUnit' not found

What am I doing wrong?

2

There are 2 best solutions below

0
On

The solution is to use OCAMLPATH

OCAMLPATH=~/ounit ocamlfind ocamlc -o test -package oUnit -I ~/ounit/oUnit -linkpkg -g foo.ml test.ml
0
On

You can install OPAM without root quite easily. For example, my Travis CI scripts install OPAM onto their non-root container systems like this:

wget https://downloads.sourceforge.net/project/zero-install/0install/2.8/0install-linux-x86_64-2.8.tar.bz2
tar xjf 0install-linux-x86_64-2.8.tar.bz2
cd 0install-linux-x86_64-2.8
./install.sh home
export PATH=$HOME/bin:$PATH
0install add opam http://tools.ocaml.org/opam.xml

(the advantage of installing via 0install is that you will get updates to opam automatically, and the 0install binaries of opam work on a wider range of systems than the official binaries)