From: Alessandro Baretta <alex@baretta.com>
To: Dmitry Boulytchev <db@mail.tepkom.ru>, Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Reference to undefined global using Dynlink module.
Date: Fri, 29 Nov 2002 00:40:53 +0100 [thread overview]
Message-ID: <3DE6A985.4000602@baretta.com> (raw)
In-Reply-To: <115614851699.20021128200805@mail.tepkom.ru>
Dmitri Boulytchev wrote:
> Hello everybody,
>
> I didn't get as answer browsing the archive so I decided to ask.
>
> How to avoid "Reference to undefined global ***" error during
> loading *.cmo via Dynlink module?
I had the same problem so I am competent on the subject. I
bet your code looks like the following:
a.ml
***********
open Dynlink
let foo = <whatever>
...
let _ = loadfile "b.cmo"
b.ml
***********
... A.foo ...
^
|
|
Thi is your problem. When you try to access A.foo, module A
has not completed initialization, so it's values appear to
be yet undefined to all other modules.
What you have to do is create a main.ml file which is
initialized last--that is, linked last--where you call the
Dynlink library to load b.ml. Here's how to do it:
a.ml
***************
let foo = <whatever>
b.ml
***************
... A.foo ....
main.ml
***************
open Dynlink
let _ = loadfile "b.cmo"
Makefile
*******************
all : dynlinked_prog b.cmo
b.cmo : b.ml
ocamlc -c b.ml
dynlinked_prog: a.ml main.ml
ocamlc -o $@ a.ml main.ml
# notice the order in which the files are compiled
*******************
When you run make you get an executable and a CMO. When you
run the executable, all the modules that are statically
linked into it are initialized in the order they were
specified in. So first A is initialized (and A.foo is
defined); then, main is initialized (and Dynlink.loadfile is
called). Thus, when loadfile is called, no dynamic linking
error occurs.
Alex
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
prev parent reply other threads:[~2002-11-28 23:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-28 17:08 Dmitri Boulytchev
2002-11-28 23:40 ` Alessandro Baretta [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=3DE6A985.4000602@baretta.com \
--to=alex@baretta.com \
--cc=caml-list@inria.fr \
--cc=db@mail.tepkom.ru \
/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