Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 528

How can I reliably load shared libraries from dune unit tests?

$
0
0

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)RanFile "test/dune", line 2, characters 7-18:2 |  (name testname)           ^^^^^^^^(cd _build/default/test && ./testname.bc)Fatal error: cannot load shared library dlltlapm_lib_stubsReason: 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?


Viewing all articles
Browse latest Browse all 528

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>