Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Kenichi Asai <asai@is.ocha.ac.jp>
To: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] a simple example of compiler-libs.toplevel?
Date: Wed, 15 Apr 2026 21:45:47 +0900	[thread overview]
Message-ID: <ad-IewXpM5HagXjC@is.ocha.ac.jp> (raw)
In-Reply-To: <CANhEzE5tOqq7JXA47tmkQcnF6Bz70eU8jPBT+=+g2EwQ7cNf6Q@mail.gmail.com>

Five years ago, I asked a question to this mailing list on how to
create a copy of the OCaml toplevel using compiler-libs (so that I can
customize it).  I am trying it again.  The thread is here:

https://inbox.vuxu.org/caml-list/CANhEzE5tOqq7JXA47tmkQcnF6Bz70eU8jPBT+=+g2EwQ7cNf6Q@mail.gmail.com/T/

What I did is to copy the necessary files from the OCaml source (I am
working on OCaml 4.14.2.):

topstart.ml, topmain.ml, toploop.ml, topeval.ml, topdirs.ml
topcommon.ml, trace.ml, genprintval.ml

rename them to my_topstart.ml, my_topmain.ml, etc, rename all the
module references to the new ones (My_toploop instead of Toploop, etc.)
and compiled them with compiler-libs.  See the toplevel1 directory of:

https://github.com/kenichi-asai/toplevel-experiment

However, when I compile them (by "make"), and execute the binary, I get:

$ ./toplevel
OCaml version 4.14.2
Enter #help;; for help.

# let a = 3;;
Error: Reference to undefined global `Toploop'
#

Why does this happen?

When I search for "Toploop" in the OCaml source outside the toplevel
directory, I found lambda/translmod.ml mentions it:

let toploop_ident = Ident.create_persistent "Toploop"

Does this mean the toplevel must be given by the Toploop module
instead of My_toploop?

As a second attempt, I created the toplevel2 directory of the above
repository, where I did not rename files to "my_*" but used the
original names.  When I compiled them and execute the binary, I get
segmentation fault (!):

$ ./toplevel
OCaml version 4.14.2
Enter #help;; for help.

# let a = 3;;
Segmentation fault
$

What's wrong?  How can I create a copy of the OCaml toplevel using
compiler-libs?  Any help appreciated.

Another question.  I also want to use dune to compile, instead of
OCamlMakefile.  I provided dune and dune_project files in the
repository, but when I execute dune build, I obtain the following.
What am I doing wrong?

$ dune build
File "dune", line 2, characters 7-18:
2 |  (name my_topstart)
           ^^^^^^^^^^^
Undefined symbols for architecture x86_64:
  "_caml_get_current_environment", referenced from:
      _camlDune__exe__My_topmain__fun_2483 in dune__exe__My_topmain.o
      _camlDune__exe__My_topmain__1 in dune__exe__My_topmain.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

Thank you in advance!

-- 
Kenichi Asai

      reply	other threads:[~2026-04-15 12:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-05  5:05 Kenichi Asai
2021-03-05  9:44 ` Jeremie Dimino
2021-03-05 14:03   ` Kenichi Asai
2021-03-05 17:11     ` Jeremie Dimino
2026-04-15 12:45       ` Kenichi Asai [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=ad-IewXpM5HagXjC@is.ocha.ac.jp \
    --to=asai@is.ocha.ac.jp \
    --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