caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: paul.lachat@edu.univ-fcomte.fr
To: caml-list@inria.fr
Subject: [Caml-list] [Question] Compile and link program who use Toploop
Date: Mon, 10 Apr 2017 14:55:56 +0200 (CEST)	[thread overview]
Message-ID: <1200659935.12485491.1491828956000.JavaMail.zimbra@edu.univ-fcomte.fr> (raw)

[-- 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 --]

             reply	other threads:[~2017-04-10 12:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-10 12:55 paul.lachat [this message]
2017-04-10 13:02 ` Nicolás Ojeda Bär

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1200659935.12485491.1491828956000.JavaMail.zimbra@edu.univ-fcomte.fr \
    --to=paul.lachat@edu.univ-fcomte.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).