My configuration is as follows:
OCaml is installed by Homebrew, according to its default recipe. It lives in /usr/local/Cellar/objective-caml/3.12.0/[bin,lib,share]
, the contents of which are symlinked out to /usr/local/[bin,lib,share]
.
A 3rd party library (LLVM) installed symlinks into /usr/local/lib/ocaml/*
. Critically, /usr/local/lib/ocaml
is itself not a symlink to the Homebrew Cellar, but a folder containing links to the individual files under the OCaml Cellar path, so these 3rd party library files are in the /usr/local/lib/ocaml/
path but not the original path of
The standard OCaml compilers/interpreter/build tools consistently fail to find these 3rd party libraries unless they are explicitly pointed there (e.g. with ocamlbuild -cflags -I,/usr/local/lib/ocaml
).
ld.conf
lists:
/usr/local/lib/ocaml/stublibs
/usr/local/lib/ocaml
/usr/local/lib/ocaml/site-lib/pcre
which would seem to suggest that the compiler search path be set correctly, but I am not familiar with the inner workings of the toolchain.
configure
and installation process (i.e. assuming that the problem is OCaml, as configured, assuming its actual lib path is /usr/local/Cellar/objective-caml/3.12.0/lib/ocaml
rather than /usr/local/lib/ocaml
), is it possible to force explicitly add additional search paths outside the --prefix
during configuration?Indeed as ygrek pointed out, the answer is ocamlfind
. OCamlfind maintains a list of findlib-enabled¹ OCaml packages installed on your system, and it's easy to link them. Use
ocamlfind list
To get the list of packages, which can be piped to grep
etc.
ocamlfind query mypackage
To get the installation path for the package (for more see ocamlfind query --help
)
ocamlfind ocamlc -package mypackage .....
To compile something using the package as a dependency (-linkpkg
is used in the final linking step to build the executable, you don't need it with -c -o foo.cmo
for example).
ocamlfind
can also be used through ocamlbuild. Prior to ocaml 3.12 you add to hack a bit the myocamlbuild.ml
file (link), but since 3.12 it's dead easy: use package(foo)
in the ocamlbuild tags if you want to use ocamlfind's package foo
, and add option -use-ocamlfind
to ocamlbuild
's invocation.
¹: ocamlfind is the lingua franca of OCaml packages. If some of your third libraries don't register themselves through ocamlfind, you should hunt them, write a META file (it's easy), and send it to the library maintainer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With