Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynlink with local modules #3708

Closed
vicuna opened this issue Jun 29, 2005 · 3 comments
Closed

dynlink with local modules #3708

vicuna opened this issue Jun 29, 2005 · 3 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jun 29, 2005

Original bug ID: 3708
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hi,

when I dynlink something like

let a = 
  let module M = MLast in M.loc_of_expr

I get a dynlink error "undefined global MLast. The equivalent

let a = MLast.loc_of_expr

load fine.

I append three files to reproduce the problem. Check with

./dynlink_main dynlink_nonloc.cmo
./dynlink_main dynlink_loc.cmo

Bye,

Hendrik


let main () =
Dynlink.loadfile Sys.argv.(1)
;;

try
main ()
with
| Dynlink.Error e as ex ->
prerr_endline(Printexc.to_string ex);
Printf.fprintf stderr "Dynlink Error %s\n" (Dynlink.error_message e)
| x -> prerr_endline(Printexc.to_string x);

(*** Local Variables: )
(
compile-command: "ocamlc -o dynlink_main dynlink.cma dynlink_main.ml" )
(
End: ***)

let a =
let module M = MLast in M.loc_of_expr

(*** Local Variables: )
(
compile-command: "ocamlc -I +camlp4 -c dynlink_loc.ml" )
(
End: ***)

let a = MLast.loc_of_expr

(*** Local Variables: )
(
compile-command: "ocamlc -I +camlp4 -c dynlink_nonloc.ml" )
(
End: ***)


@vicuna
Copy link
Author

vicuna commented Jul 20, 2005

Comment author: administrator

when I dynlink something like

let a =
  let module M = MLast in M.loc_of_expr

I get a dynlink error "undefined global MLast. The equivalent

let a = MLast.loc_of_expr

load fine.

Generally speaking, when a program dynlinks a module A that references
a module B (B = MLast in your example), you must ensure that an
implementation of B is available, e.g. by linking B.cmo statically with
the program. Otherwise, you'll get "undefined global B" errors.

This is not the case in your program because dynlink_main was not
linked with an implementation of MLast. So, the error with the first
module above is normal.

Now, why is it that the second module causes no errors? Well,
MLast.loc_of_expr is a primitive ("external" declaration in MLast.mli)
and therefore is inlined at point of use in the second module, and
there are no references to MLast in the generated .cmo file.

Best regards,

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Jul 20, 2005

Comment author: administrator

Normal behaviour, see follow-up for explanations.

@vicuna vicuna closed this as completed Jul 20, 2005
@vicuna
Copy link
Author

vicuna commented Jul 20, 2005

Comment author: administrator

Xavier Leroy writes:
Date: Wed, 20 Jul 2005 15:23:17 +0200

Generally speaking, when a program dynlinks a module A that references
a module B (B = MLast in your example), you must ensure that an
implementation of B is available, e.g. by linking B.cmo statically with
the program. Otherwise, you'll get "undefined global B" errors.

OK, then I would like to turn this into a feature wish: Please
provide an implementation mLast.cmo in the next distribution. It
is as easy as

ocamlc -c -pp "camlp4r -impl" -impl mLast.mli

although it might be preferably to have a save object file
mLast.cmo.

Bye,

Hendrik

@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant