caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolás Ojeda Bär" <nicolas.ojeda.bar@lexifi.com>
To: paul.lachat@edu.univ-fcomte.fr
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] [Question] Compile and link program who use Toploop
Date: Mon, 10 Apr 2017 15:02:16 +0200	[thread overview]
Message-ID: <CADK7aFPrZfkobFjhrdoP1vgpAPgwhXQAAn-7yBbMgaPOKjmzXw@mail.gmail.com> (raw)
In-Reply-To: <1200659935.12485491.1491828956000.JavaMail.zimbra@edu.univ-fcomte.fr>

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

      reply	other threads:[~2017-04-10 13:02 UTC|newest]

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

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=CADK7aFPrZfkobFjhrdoP1vgpAPgwhXQAAn-7yBbMgaPOKjmzXw@mail.gmail.com \
    --to=nicolas.ojeda.bar@lexifi.com \
    --cc=caml-list@inria.fr \
    --cc=paul.lachat@edu.univ-fcomte.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).