Reputation: 23
i got this in my prog.ml:
#require "batteries";;
#require "Base";;
open Base;;
open Batteries;;
...
When I try to compile:
ocamlc prog.ml -o prg
it returns the following error:
1 | #require "batteries";;
^ Error: Syntax error
what is the correct command to compile the program?
Upvotes: 1
Views: 594
Reputation: 66823
Lines starting with #directive
are meaningful only in the toplevel. They're not part of the actual syntax of OCaml. They just tell the toplevel to do various things that are useful during an interactive session.
If you're going to compile the code (rather than interacting with it in the toplevel), you just need to make sure the modules are accessible to the compiler. You can use a fancy build system, or you can use the -I
flag that tells the compiler where to look for modules.
(You also have to remove the #directive
lines from your source code, of course.)
Upvotes: 2