I've looked at this question -- How do I add an OCaml library reference to a Reason code file? -- which shows how to add an OCaml library to a ReasonML project. But it doesn't seem to be working for me. Part of the problem is that I don't really know what esy and dune are doing, and stepping through the examples that tell me what to type is all very well...except I don't know why I'm typing it.
I've got a dune file:
(executable (public_name graphics_example.exe) (name graphics_example) (libraries graphics))
I've got a package.json file copied from the hello-reason example:
{"name": "hello-reason","version": "0.1.0","description": "Example Reason Esy Project","license": "MIT","esy": {"build": "dune build -p #{self.name}","buildDev": "dune build --promote-install-files --root . --only-package #{self.name}","NOTE": "Optional release Section. Customizes result of `esy release`","release": { "rewritePrefix": true, "bin": [ "Hello" ] },"buildEnv": { "ODOC_SYNTAX": "re" } },"scripts": {"test": "esy x Hello","format": "esy dune build @fmt --auto-promote","doc": "esy dune build @doc" },"dependencies": {"@opam/dune": "*","@opam/reason": "*","ocaml": "5.x" },"devDependencies": {"@opam/ocaml-lsp-server": "*","@opam/merlin": "*","@opam/odoc": "*" }}
And I have a ReasonML file, graphics_example.re:
open Graphics;open_graph("");set_window_title("SPIKE");ignore(wait_next_event([Button_down]));
And if I type
dune exec ./graphics_example.exe
My program actually runs and shows a graphics window. (I installed XQuartz on my Mac M1 to make this happen, following suggestions during earlier experiments.) But if I run esy
, I get this:
info esy 0.8.0 (using package.json)File "dune", line 4, characters 12-20:4 | (libraries graphics)) ^^^^^^^^Error: Library "graphics" not found.-> required by /Users/jhughes/Documents/Projects/ReasonML/hello-reason-master/_esy/default/store/b/hello_reason-e15a11c9/default/graphics_example.exe-> required by alias all-> required by alias defaulterror: command failed: 'dune''build''--promote-install-files''--root''.''--only-package''hello-reason' (exited with 1)esy-build-package: exiting with errors above...error: build failed with exit code: 1esy: exiting due to errors above
So I don't understand what I might have done to make a graphics program work even though I can't find the graphics library, and I don't understand why I cannot find the graphics library in the first place, since it's a standard library in OCaml.
I do know that if I remove "graphics" as a library from the dune
file, then dune exec ./graphics_example.exe
no longer works, so it appears that dune is somehow finding the library that esy cannot find, or ... I don't know. I'd appreciate any clarity at all.