Reputation: 1747
I build ocaml from source,first ./configure,then make world
so i have a ocamlc program under the source folder
I write a simple program a.ml:
let a=1
then ./ocamlc a.ml
but got error:Unbound mudule Pervasives
I tried to use
./ocamlc -I +compiler-libs ./stdlib/stdlib.cma a.ml
and
./ocamlc -I +compiler-libs ./compilerlibs/*.cma a.ml
but got this error too
so how to build a.ml use the new compiled ocamlc?Thanks
Upvotes: 0
Views: 242
Reputation: 9030
Usually OCaml compiler is supposed to be installed by make install
before using it.
Having said that, there is a way to use the compiler without installing it:
$ boot/ocamlrun ./ocamlc -nostdlib -I stdlib -c a.ml
boot/ocamlrun
is required to use the correct bytecode interpreter. It may work without it, but it may be just by luck: the interpreter specified in your new ./ocamlc
shebang may pre-exists and may be compatible with your new compiler.-nostdlib
is required not to use the standard library already installed.-I stdlib
is required to load the correct standard library compiled with your new ocamlc
compiler.If you need to use other libraries add appropriate include and linking options.
Everything is explained in http://caml.inria.fr/pub/docs/manual-ocaml/comp.html , so please read it.
If you want to use compiler libraries without installing them, you have to not only link with one or several *.cma
files under ./compilerlibs
, but also add -I
options of directories of compiler sources: -I parsing -I utils -I typing ...
, so that ./ocamlc
can find the required *.cmi
files. (If you want to play with the compiler libs, you should be familiar with how OCaml compiler finds modules first of all...)
Upvotes: 4