Make opam find a per-user installed C library

this may be easy but i could not see an immediate way to do it.

i’m on a linux machine without admin rights. i have a recent copy of GSL installed in a directory other than the system-wide standard (the sysadmin did this for me, it’s in /opt/gsl-2.4).

how can i

  1. tell opam to install the gsl wrapper with correct linking to this version of GSL
  2. tell ocamlbuild to link correctly afterwards?

i would love to just set some $LD_LIBRARY_PATH and be done with it but that does not seem to be enough?

1 Like

Opam doesn’t really have knowledge about the C libraries, so it’s basically down to the packages’ build systems. Setting LD_LIBRARY_PATH (and possibly CPATH) should work, but depending on the ./configure scripts, some might depend on pkg-config, in which case you might have to check with e.g. PKG_CONFIG_PATH too.

All else failing, you might have to tweak the conf-gsl package by hand to make it accept your installation (use opam pin --edit). Opam 2 allows to add setenv: definitions in opam files, so that could be used to avoid having to set the variables each time (or from your .profile) too.

thanks! indeed in my case setting both PKG_CONFIG_PATH and LD_LIBRARY_PATH to the appropriate subdirectories of /opt/gsl-2.4 worked!