简体   繁体   中英

How to include data file in dune build for OCaml program?

I have a project where myprogram.ml depends on an external data file, mydata.dat -

  • myproject/
    • dune
    • myprogram.ml
    • mydata.dat

I have a dune file -

(executable
 (name myprogram))

When I run the program -

$ dune build myprogram.exe
$ cd _build/default
$ ./myprogram.exe
Fatal error: exception Sys_error("./mydata.dat: No such file or directory")

I tried adding a rule -

(rule
 (targets "./mydata.dat")
 (action (copy "./mydata.dat" "./mydata.dat")))

But obviously I'm doing it wrong -

$ dune build myprogram.exe
Error: Multiple rules generated for _build/default/mydata.dat:
- file present in source tree
- dune:4
Hint: rm -f mydata.dat

How can I have dune include mydata.dat in my projects build so myprogram.exe always has access to it?

Just replace ./mydata.dat with mydata.dat in myprogram.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