[Dream] my first try

I am willing to test the Dream webframework for a small project.

Installing it took me some time because of the recent ssl dependency issue. Then I am trying to reproduce the 01-hello tutorial by copy/paste the source code in a project I build myself. I have a linking error I don’t know how to resolve (@antron ). Help appreciated.

My ocaml setup is on a windows box.

opam exec -- dune init project test_dream

I modify the dune file:

(executable
 (public_name test_dream)
 (name main)
 (libraries test_dream dream))

copy / paste the source code into main.ml

let () =
  Dream.run (fun _ ->
    Dream.html "Good morning, world!")

and build

PS H:\OCaml\test_dream> (& opam env) -split '\r?\n' | ForEach-Object { Invoke-Expression $_ }
PS H:\OCaml\test_dream> opam exec -- dune build                  
File "bin/dune", line 3, characters 7-11:
3 |  (name main)
           ^^^^
/bin/bash: C:UsersNAlec~1AppDataLocalTempbuild_967b29_dunelongcmd8d30f6: No folder or file of this type
** Fatal error: Error during linking

File "caml_startup", line 1:
Error: Error during linking (exit code 2)
PS H:\OCaml\test_dream> 

If it were necessary :

PS H:\OCaml\test_dream> opam show dream

<><> dream: information on all versions <><><><><><><><><><><><><><><><><><>  🐫 
name                   dream
all-installed-versions 1.0.0~alpha7 [default]
all-versions           1.0.0~alpha1  1.0.0~alpha2  1.0.0~alpha3  1.0.0~alpha4  1.0.0~alpha5  1.0.0~alpha6  1.0.0~alpha7

<><> Version-specific details <><><><><><><><><><><><><><><><><><><><><><><>  🐫 
version      1.0.0~alpha7
repository   default
url.src      "https://github.com/aantron/dream/releases/download/1.0.0-alpha7/dream-1.0.0-alpha7.tar.gz"
url.checksum "sha256=b715cecf7e2b249335c8d1cd22c3e87017e40c0556774d209f338f9d78388c86"
homepage     "https://github.com/aantron/dream"
doc          "https://aantron.github.io/dream"
bug-reports  "https://github.com/aantron/dream/issues"
dev-repo     "git+https://github.com/aantron/dream.git"
authors      "Anton Bachin <antonbachin@yahoo.com>"
maintainer   "Anton Bachin <antonbachin@yahoo.com>"
license      "MIT"
tags         "http" "web" "framework" "websocket" "graphql" "server" "http2" "tls"
depends      "base-unix"
             "bigarray-compat"
             "camlp-streams"
             "caqti" {>= "2.0.0"}
             "caqti-lwt" {>= "2.0.0"}
             ("conf-libev" {os != "win32"} | "ocaml" {os = "win32"})
             "cstruct" {>= "6.0.0"}
             "digestif" {>= "0.7"}
             "dream-httpaf" {>= "1.0.0~alpha3"}
             "dream-pure" {>= "1.0.0~alpha2"}
             "dune" {>= "2.7.0"}
             "fmt" {>= "0.8.7"}
             "graphql_parser"
             "graphql-lwt"
             "lambdasoup" {>= "0.6.1"}
             "lwt"
             "lwt_ppx" {>= "1.2.2"}
             "lwt_ssl"
             "logs" {>= "0.5.0"}
             "magic-mime"
             "markup" {>= "1.0.2"}
             "mirage-clock" {>= "3.0.0"}
             "mirage-crypto" {>= "1.0.0"}
             "mirage-crypto-rng" {>= "1.0.0"}
             "mirage-crypto-rng-lwt"
             "multipart_form" {>= "0.4.0"}
             "multipart_form-lwt"
             "ocaml" {>= "4.08.0"}
             "ptime" {>= "0.8.1"}
             "ssl" {>= "0.5.8"}
             "uri" {>= "4.2.0"}
             "yojson"
             "alcotest" {with-test}
             "bisect_ppx" {with-test & >= "2.5.0"}
             "caqti-driver-postgresql" {with-test}
             "caqti-driver-sqlite3" {with-test}
             "crunch" {with-test}
             "html_of_jsx" {with-test}
             "js_of_ocaml" {with-test}
             "js_of_ocaml-ppx" {with-test}
             "ppx_expect" {with-test & >= "v0.15.0"}
             "ppx_yojson_conv" {with-test}
             "reason" {with-test}
             "tyxml" {with-test & >= "4.5.0"}
             "tyxml-jsx" {with-test}

test_dream is not needed here. It’s the name of your project and the public name of your executable. The libraries field lists the dependency libraries. Your executable is not depending on itself.

Try copying and running exactly the 1-hello example as shown in the Dream repo: dream/example/1-hello at master · aantron/dream · GitHub

It is designed to be a complete, self-contained project. You don’t need to initialize a new project with dune init project. Just try running the project in the above directory. Follow the instructions in the readme shown in my link.

I have copied the exact 1-hello example and build it with the same error.

The test_dream in the libraries is added by dune at initialisation of projects and I don’t think this is the issue.

PS H:\OCaml\test_dream> opam exec -- dune build
File "dune", line 2, characters 7-12:
2 |  (name hello)
           ^^^^^
/bin/bash: C:UsersNAlecAppDataLocalTempbuild_71f7d1_dunelongcmd9f3bd8: Aucun fichier ou dossier de ce type
** Fatal error: Error during linking

File "caml_startup", line 1:
Error: Error during linking (exit code 2)
PS H:\OCaml\test_dream> 
1 Like

Looks like all the backslash characters have been dropped. Maybe some part of your system is mixing up file paths. I think this is an issue where we would need to know how exactly you installed OCaml/opam, which shell you are using (cmd.exe? PowerShell?), and so on. Looks like the OCaml installation itself has an issue.

You may be experiencing what is covered in this thread.

2 Likes

Indeed ! Using @b-valdez trick solved the issue for me. I had WSL installed as well.

1 Like