* [Caml-list] Reference to undefined global using Dynlink module.
@ 2002-11-28 17:08 Dmitri Boulytchev
2002-11-28 23:40 ` Alessandro Baretta
0 siblings, 1 reply; 2+ messages in thread
From: Dmitri Boulytchev @ 2002-11-28 17:08 UTC (permalink / raw)
To: caml-list
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?
To be more precise: the loading foo.cmo uses Num module. All
interfaces (including "Num") are added in the client program. On
loading I get an error "Reference to undefined global Num".
Why am I wrong and whether am I wrong at all? :))
Best regards,
Dmitri Boulytchev,
St.Petersburg State University.
-------------------
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Reference to undefined global using Dynlink module.
2002-11-28 17:08 [Caml-list] Reference to undefined global using Dynlink module Dmitri Boulytchev
@ 2002-11-28 23:40 ` Alessandro Baretta
0 siblings, 0 replies; 2+ messages in thread
From: Alessandro Baretta @ 2002-11-28 23:40 UTC (permalink / raw)
To: Dmitry Boulytchev, Ocaml
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-28 23:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-28 17:08 [Caml-list] Reference to undefined global using Dynlink module Dmitri Boulytchev
2002-11-28 23:40 ` Alessandro Baretta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox