caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [Question] Compile and link program who use Toploop
@ 2017-04-10 12:55 paul.lachat
  2017-04-10 13:02 ` Nicolás Ojeda Bär
  0 siblings, 1 reply; 2+ messages in thread
From: paul.lachat @ 2017-04-10 12:55 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1432 bytes --]

Hello, 

I would like to use functions of the toplevel (https://github.com/ocaml/ocaml/blob/trunk/toplevel/toploop.ml) 

I've tried to compile this code just to understand how I can link the toploop file with my program : 
____ 
test.ml : 

let _ = 
let lb = Lexing.from_string "let x = 10;;" in 
let ppf = Format.std_formatter in 
try 
List.iter 
(fun phr -> 
if not (Toploop.execute_phrase false ppf phr) then raise Exit) 
(!Toploop.parse_use_file lb) 
with 
| Exit -> () 
| x -> Errors.report_error ppf x 

____ 

I've test : 

[-] ocamlc -I +compiler-libs -o test.out test.ml 

[*] File "test.ml", line 1: 
Error: Error while linking test.cmo: 
Reference to undefined global `Toploop' 

____ 

So I create test.cmo with : 
[-] ocamlc -I +compiler-libs -c test.ml, but I don't know where to find "toploop.cmo". 

I use Ocaml 4.03.0 with Opam. 
In ".opam/4.03.0/lib/ocaml/compiler-libs/" I have "toploop.cmi", "toploop.cmti" and "toploop.cmt", but no "toploop.cmo" to link to the program. 

I've seen this file ".opam/4.03.0/lib/ocaml/compiler-libs/ocamltoplevel.cma", but I don't know if it's usefull. 

I think it's possible to use Toploop. In this post, https://stackoverflow.com/questions/33291754/eval-a-string-in-ocaml, they seems to have find a way to compile a program who use Toploop. But I would like, if possible, to avoid dependecys like ocamlbuild. 

____ 

So, I would like to know how I can compile this program ? 

[-- Attachment #2: Type: text/html, Size: 2030 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] [Question] Compile and link program who use Toploop
  2017-04-10 12:55 [Caml-list] [Question] Compile and link program who use Toploop paul.lachat
@ 2017-04-10 13:02 ` Nicolás Ojeda Bär
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolás Ojeda Bär @ 2017-04-10 13:02 UTC (permalink / raw)
  To: paul.lachat; +Cc: OCaml Mailing List

[-- Attachment #1: Type: text/plain, Size: 1887 bytes --]

Dear Paul,

You just need to link in ocamltoplevel.cma by adding it to the command-line

  ocamlc -I +compiler-libs ocamltoplevel.cma -o test.out test.ml

(the compiler will be able to find this file thanks to the "-I
+compiler-libs" flag).

Cheers,
Nicolas

On Mon, Apr 10, 2017 at 2:55 PM, <paul.lachat@edu.univ-fcomte.fr> wrote:

> Hello,
>
> I would like to use functions of the toplevel (https://github.com/ocaml/
> ocaml/blob/trunk/toplevel/toploop.ml)
>
> I've tried to compile this code just to understand how I can link the
> toploop file with my program :
> ____
> test.ml :
>
> let _ =
>     let lb = Lexing.from_string "let x = 10;;" in
>     let ppf = Format.std_formatter in
>     try
>     List.iter
>       (fun phr ->
>         if not (Toploop.execute_phrase false ppf phr) then raise Exit)
>       (!Toploop.parse_use_file lb)
>     with
>     | Exit -> ()
>     | x -> Errors.report_error ppf x
>
> ____
>
> I've test :
>
> [-] ocamlc -I +compiler-libs -o test.out test.ml
>
> [*] File "test.ml", line 1:
>     Error: Error while linking test.cmo:
>     Reference to undefined global `Toploop'
>
> ____
>
> So I create test.cmo with :
> [-] ocamlc -I +compiler-libs -c test.ml, but I don't know where to find
> "toploop.cmo".
>
> I use Ocaml 4.03.0 with Opam.
> In ".opam/4.03.0/lib/ocaml/compiler-libs/" I have "toploop.cmi",
> "toploop.cmti" and "toploop.cmt", but no "toploop.cmo" to link to the
> program.
>
> I've seen this file ".opam/4.03.0/lib/ocaml/compiler-libs/ocamltoplevel.cma",
> but I don't know if it's usefull.
>
> I think it's possible to use Toploop. In this post,
> https://stackoverflow.com/questions/33291754/eval-a-string-in-ocaml, they
> seems to have find a way to compile a program who use Toploop. But I would
> like, if possible, to avoid dependecys like ocamlbuild.
>
> ____
>
> So, I would like to know how I can compile this program ?
>

[-- Attachment #2: Type: text/html, Size: 3122 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-10 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10 12:55 [Caml-list] [Question] Compile and link program who use Toploop paul.lachat
2017-04-10 13:02 ` Nicolás Ojeda Bär

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).