Difference between module and package Ocaml
Asked Answered
S

2

6

I'm basically trying to follow this stackoverflow answer located in this post:

What is the best module for HttpRequest in OCaml

and I'm running in to problems. When I am trying to run a single file with just

open Lwt ;; 

I am getting and error saying it is an unbound module. I have run the following opam instruction:

opam install lwt

and it did install the correct package.

So I think the problem is the difference between a module and a package, which I don't really understand. I was looking at this question as a possible answer, but I wasn't sure if it was what I needed.

Unbound modules in OCaml

Thanks for the input guys, I'm new to Ocaml and I'm trying to learn the ins and outs of building something.

Straley answered 22/5, 2013 at 1:7 Comment(1)
how are you compiling it?. I'd suggest using _oasis (see oasis.forge.ocamlcore.org/quickstart.html) for generating the appropriate build script for you.Cultivable
T
5

To use a "package", you must tell the compiler about it explicitly. Unbound module in OCaml usually means one of two things: your made a typo of the module name, or you failed to set a proper module search path. What compiler options do you use?

If you use ocamlfind, the compilation should look like:

ocamlfind ocamlc -package lwt -c mymodule.ml

this instructs the compiler to try to find modules in lwt package installation directory, in addition to the default ones.

if you do not use ocamlfind.... well, use ocamlfind.

Treasury answered 22/5, 2013 at 3:54 Comment(2)
I tried what you suggested. I checked that I had installed the lwt package with opam, then ran what you have above and I am getting the same error as before. "Package lwt not found."Straley
if "opam list lwt" shows the package is installed, try "ocamlfind query lwt" to see its module path. If ocamlfind says Package 'lwt' not found, then your environment is misconfigured. Read OPAM document and check your environment variables. Anyway, if you want better answers, you must give us more details what you tried.Treasury
B
0

The command for compiling our program will be:

ocamlfind ocamlopt -o progprog -linkpkg \
  -package lablGL,sdl,sdl.sdlimage,sdl.sdlmixer,sdl.sdlttf \
  module1.ml module2.ml

As seen on: https://ocaml.org/learn/tutorials/compiling_ocaml_projects.html

Bostwick answered 21/6, 2015 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.