“Error: unbound module” in OCaml

前端 未结 2 1410
自闭症患者
自闭症患者 2021-02-13 05:03

Here\'s a simple example of using the library Cohttp:

open Lwt
open Cohttp
open Cohttp_lwt_unix

let body =
  Client.get (Uri.of_string \"http://www.reddit.com/\         


        
相关标签:
2条回答
  • 2021-02-13 05:36

    Try to compile it like this ...

    ocamlfind ocamlopt -o my_test \ 
       -linkpkg \ 
       -package lwt,cohttp,cohttp-lwt-unix \
       -thread 
        my_test.ml
    
    0 讨论(0)
  • 2021-02-13 05:47

    You have several options depending on your needs.

    1) If you want to create a full project for your binary I recommend looking at jbuilder. Here is a very nice guide that explains the environment/project configuration step-by-step: OCaml for the impatient.

    2) Another option is to compile the binary directly as you were trying to do:

    ocamlbuild -pkg lwt -pkg cohttp-lwt-unix my_test1.native
    

    Note that you need to have a file named my_test1.ml to generate the requested my_test1.native.

    3) And finally for quick scripts I find it handy to be able to ask the OCaml interpreter to load the dependencies directly in the source file. Just add the following to the beginning of your file:

    #use "topfind";;
    #require "lwt";;
    #require "cohttp-lwt-unix";;
    

    And then run ocaml my_test1.ml.


    Hope this helps! :)

    Also looking at the command not found errors you are getting I can suggest to make sure your environment is correctly configured. The Real World OCaml book has a wiki page for that: https://github.com/realworldocaml/book/wiki/Installation-Instructions

    0 讨论(0)
提交回复
热议问题