cs3110 / textbook

The CS 3110 Textbook, "OCaml Programming: Correct + Efficient + Beautiful"
Other
720 stars 132 forks source link

Issue on page /chapters/basics/compiling.html #84

Closed wbwqq closed 2 years ago

wbwqq commented 2 years ago

dune build hello.exe

Doesn't work. This is the error message:

Error: I cannot find the root of the current workspace/project.
If you would like to create a new dune project, you can type: 

    dune init project NAME

Otherwise, please make sure to run dune inside an existing project or
workspace. For more information about how dune identifies the root of the
current workspace/project, please refer to
https://dune.readthedocs.io/en/stable/usage.html#finding-the-root

It seems that the manual doesn't mention the fact that a dune project needs to be initialized.

wbwqq commented 2 years ago

Even after running dune init project hello, when I try to run dune build hello.exe, I get the same error message as above Error: I cannot find the root of the current workspace/project....etc... Here is the list of files in the directory:

_build/
hello/
dune
dune_project
hello.ml
clarksmr commented 2 years ago

Probably the same root cause as #80: the Dune version has changed since the last textbook release. I'm looking into it.

wbwqq commented 2 years ago

Thanks! In the meantime if anyone has a similar issue, I made a small bash script as a workaround:

file=$1
filename=${file%.*}
rm -rf $filename-ocaml/
mkdir $filename-ocaml
cp $file $filename-ocaml/$file
cd $filename-ocaml
ocamlc -o $filename.byte $file
cd ..
./$filename-ocaml/$filename.byte

To compile and run a file called hello.ml for example, if the above is in a file called run, just run with ./run hello.ml

clarksmr commented 2 years ago

4e36ad6 will fix this when published.

Note that there's a simpler solution than the script above: just manually create a dune-project file. No need for the entire directory infrastructure that dune init project creates.