My project layout is roughly as follows:
/
├── src/
│ ├── dune
│ ├── libname.ml
│ └── libname.mli
└── test/
├── dune
└── testname.ml
The test/dune
file contains:
(test
(name testname)
(modes byte exe)
(libraries libname)
)
So it runs the test both in bytecode and exe mode.
The library built in src
depends on a dynamically-loaded native library that is output to _build/default/src
. When I run dune runtest test --force --always-show-commandline
, I get the following output:
(cd _build/default/test && ./testname.exe)
Ran
File "test/dune", line 2, characters 7-18:
2 | (name testname)
^^^^^^^^
(cd _build/default/test && ./testname.bc)
Fatal error: cannot load shared library dlltlapm_lib_stubs
Reason: dlltlapm_lib_stubs.so: cannot open shared object file: No such file or directory
So the exe run finds the the shared library without problem, but the bytecode run does not. I can fix this by modifying OCAML_LD_LIBRARY_PATH
as follows, since the --always-show-command-line
output tells us that dune
is cd
‘ing into _build/default/test
:
CAML_LD_LIBRARY_PATH=../src:$CAML_LD_LIBRARY_PATH
but using relative paths in this way is very fragile and won’t work if I start putting tests in subdirectories of the test
dir. How can I reliably tell dune runtest
where to look for shared libraries?