简体   繁体   中英

Using ocamlfind with local directories

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?

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)

解决方案是使用OCAMLPATH

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM