caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Dynlink
@ 2015-09-09 13:09 Sébastien Hinderer
  2015-09-09 13:19 ` Olivier Andrieu
  2015-09-09 13:25 ` Gabriel Scherer
  0 siblings, 2 replies; 14+ messages in thread
From: Sébastien Hinderer @ 2015-09-09 13:09 UTC (permalink / raw)
  To: caml-list

Dear all,

It seems that, at least at some point in the past, Dynlink was not
available everywhere. For instance as far as I could see it seems it was
available for byte-code only. Is that correct? And if so, since which
OCaml version is Dynlink available for both byte-code and native-code?

Are there other environments in which Dynlink is not supported?

Many thanks for any information.

Best wishes,

Sébastien.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-09 13:09 [Caml-list] Dynlink Sébastien Hinderer
@ 2015-09-09 13:19 ` Olivier Andrieu
  2015-09-09 13:29   ` Sébastien Hinderer
  2015-09-09 13:25 ` Gabriel Scherer
  1 sibling, 1 reply; 14+ messages in thread
From: Olivier Andrieu @ 2015-09-09 13:19 UTC (permalink / raw)
  To: Sébastien Hinderer, Caml List

On Wed, Sep 9, 2015 at 3:09 PM, Sébastien Hinderer
<Sebastien.Hinderer@inria.fr> wrote:
> Dear all,
>
> It seems that, at least at some point in the past, Dynlink was not
> available everywhere. For instance as far as I could see it seems it was
> available for byte-code only. Is that correct? And if so, since which
> OCaml version is Dynlink available for both byte-code and native-code?

according to https://github.com/ocaml/ocaml/blob/trunk/Changes#L2125 :
  Objective Caml 3.11.0 (03 Dec 2008)

-- 
  Olivier

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-09 13:09 [Caml-list] Dynlink Sébastien Hinderer
  2015-09-09 13:19 ` Olivier Andrieu
@ 2015-09-09 13:25 ` Gabriel Scherer
  1 sibling, 0 replies; 14+ messages in thread
From: Gabriel Scherer @ 2015-09-09 13:25 UTC (permalink / raw)
  To: Sébastien Hinderer, caml users

According to the Changes file,
  https://github.com/ocaml/ocaml/blob/trunk/Changes
native dynlink was first introduced in 3.11.0, released in December 2008.

Its support depends on both the operating system and the architecture.
For example, natdynlink was only supported on ARM machines starting
from 4.00 (July 2012).

The current configuration code is available at
  https://github.com/ocaml/ocaml/blob/ee9d50e899f98283620db5693f6e43a340422756/configure#L634-L778
It seems to be currently supported on most x86 and x86-64 systems, but
only on Linux for PowerPC and Sparc, and only on Linux and FreeBSD for
ARM.

On Wed, Sep 9, 2015 at 3:09 PM, Sébastien Hinderer
<Sebastien.Hinderer@inria.fr> wrote:
> Dear all,
>
> It seems that, at least at some point in the past, Dynlink was not
> available everywhere. For instance as far as I could see it seems it was
> available for byte-code only. Is that correct? And if so, since which
> OCaml version is Dynlink available for both byte-code and native-code?
>
> Are there other environments in which Dynlink is not supported?
>
> Many thanks for any information.
>
> Best wishes,
>
> Sébastien.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-09 13:19 ` Olivier Andrieu
@ 2015-09-09 13:29   ` Sébastien Hinderer
  2015-09-09 13:34     ` Xavier Leroy
  0 siblings, 1 reply; 14+ messages in thread
From: Sébastien Hinderer @ 2015-09-09 13:29 UTC (permalink / raw)
  To: Caml List

Dear Olivier,

Thanks alot for your prompt and precise resopnse.

> according to https://github.com/ocaml/ocaml/blob/trunk/Changes#L2125 :
>   Objective Caml 3.11.0 (03 Dec 2008)


Indeed, the file says:

- Dynlink: on some platforms, the Dynlink library is now available in
  native code.

Is there a more precise list of platforms on which this is available?

Is there a way for a configure script to programmatically determine the
availability of the feature on one given platform?

Thanks!

Sébastien.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-09 13:29   ` Sébastien Hinderer
@ 2015-09-09 13:34     ` Xavier Leroy
  2015-09-09 13:44       ` Sébastien Hinderer
  0 siblings, 1 reply; 14+ messages in thread
From: Xavier Leroy @ 2015-09-09 13:34 UTC (permalink / raw)
  To: caml-list

On 09/09/2015 15:29, Sébastien Hinderer wrote:
> Indeed, the file says:
> 
> - Dynlink: on some platforms, the Dynlink library is now available in
>   native code.
> 
> Is there a more precise list of platforms on which this is available?

You can't get more precise than the configure script of OCaml :-)

> Is there a way for a configure script to programmatically determine the
> availability of the feature on one given platform?

Just check for the presence of dynlink.cmxa in OCaml's standard
library directory.

- Xavier Leroy

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-09 13:34     ` Xavier Leroy
@ 2015-09-09 13:44       ` Sébastien Hinderer
  2015-09-09 16:03         ` Gerd Stolpmann
  0 siblings, 1 reply; 14+ messages in thread
From: Sébastien Hinderer @ 2015-09-09 13:44 UTC (permalink / raw)
  To: caml-list

Dear Xavier,

Many thanks for your response.

> You can't get more precise than the configure script of OCaml :-)

Sure!

> > Is there a way for a configure script to programmatically determine the
> > availability of the feature on one given platform?
> 
> Just check for the presence of dynlink.cmxa in OCaml's standard
> library directory.

OK! Quitesimple,thanks.

So am I correct that the question ``is Dynlink supported'' only makes
sense when one compiles a native-code program, because this always works
for byte-code?

Thanks!

Sébastien.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-09 13:44       ` Sébastien Hinderer
@ 2015-09-09 16:03         ` Gerd Stolpmann
  2015-09-10 12:08           ` Sébastien Hinderer
  0 siblings, 1 reply; 14+ messages in thread
From: Gerd Stolpmann @ 2015-09-09 16:03 UTC (permalink / raw)
  To: Sébastien Hinderer; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1390 bytes --]

Am Mittwoch, den 09.09.2015, 15:44 +0200 schrieb Sébastien Hinderer:
> Dear Xavier,
> 
> Many thanks for your response.
> 
> > You can't get more precise than the configure script of OCaml :-)
> 
> Sure!
> 
> > > Is there a way for a configure script to programmatically determine the
> > > availability of the feature on one given platform?
> > 
> > Just check for the presence of dynlink.cmxa in OCaml's standard
> > library directory.
> 
> OK! Quitesimple,thanks.
> 
> So am I correct that the question ``is Dynlink supported'' only makes
> sense when one compiles a native-code program, because this always works
> for byte-code?

The question makes also a lot of sense for bytecode, because not all
platforms can load dll's. Bytecode that does not need additional dll's
can always be loaded.

On the command-line you can check with something like

echo '' | ocaml unix.cma -stdin

(unchecked, let's hope the error is correctly propagated). E.g. an
unsupported platform used to be Cygwin.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-09 16:03         ` Gerd Stolpmann
@ 2015-09-10 12:08           ` Sébastien Hinderer
  2015-09-10 16:57             ` Gerd Stolpmann
  0 siblings, 1 reply; 14+ messages in thread
From: Sébastien Hinderer @ 2015-09-10 12:08 UTC (permalink / raw)
  To: caml-list

Hi Gerd,

Gerd Stolpmann (2015/09/09 18:03 +0200):
> Am Mittwoch, den 09.09.2015, 15:44 +0200 schrieb Sébastien Hinderer:
> > Dear Xavier,
> > 
> > Many thanks for your response.
> > 
> > > You can't get more precise than the configure script of OCaml :-)
> > 
> > Sure!
> > 
> > > > Is there a way for a configure script to programmatically determine the
> > > > availability of the feature on one given platform?
> > > 
> > > Just check for the presence of dynlink.cmxa in OCaml's standard
> > > library directory.
> > 
> > OK! Quitesimple,thanks.
> > 
> > So am I correct that the question ``is Dynlink supported'' only makes
> > sense when one compiles a native-code program, because this always works
> > for byte-code?
> 
> The question makes also a lot of sense for bytecode, because not all
> platforms can load dll's. Bytecode that does not need additional dll's
> can always be loaded.

Okay, that's indeed a very important clarification. Thanks.
Bytecode that does not need addiional dlls means bytecode that does not
require any Clibrary, right?

Does somebody know what are the platforms that can not load dlls?

Thanks a lot Gerd for what you have explained.

Sébastien.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2015-09-10 12:08           ` Sébastien Hinderer
@ 2015-09-10 16:57             ` Gerd Stolpmann
  0 siblings, 0 replies; 14+ messages in thread
From: Gerd Stolpmann @ 2015-09-10 16:57 UTC (permalink / raw)
  To: Sébastien Hinderer; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2202 bytes --]

Am Donnerstag, den 10.09.2015, 14:08 +0200 schrieb Sébastien Hinderer:
> Hi Gerd,
> 
> Gerd Stolpmann (2015/09/09 18:03 +0200):
> > Am Mittwoch, den 09.09.2015, 15:44 +0200 schrieb Sébastien Hinderer:
> > > Dear Xavier,
> > > 
> > > Many thanks for your response.
> > > 
> > > > You can't get more precise than the configure script of OCaml :-)
> > > 
> > > Sure!
> > > 
> > > > > Is there a way for a configure script to programmatically determine the
> > > > > availability of the feature on one given platform?
> > > > 
> > > > Just check for the presence of dynlink.cmxa in OCaml's standard
> > > > library directory.
> > > 
> > > OK! Quitesimple,thanks.
> > > 
> > > So am I correct that the question ``is Dynlink supported'' only makes
> > > sense when one compiles a native-code program, because this always works
> > > for byte-code?
> > 
> > The question makes also a lot of sense for bytecode, because not all
> > platforms can load dll's. Bytecode that does not need additional dll's
> > can always be loaded.
> 
> Okay, that's indeed a very important clarification. Thanks.
> Bytecode that does not need addiional dlls means bytecode that does not
> require any Clibrary, right?

...not any _additional_ C library. If the C library is already
(statically) linked into the main executable, the loaded bytecode can
use it.

> Does somebody know what are the platforms that can not load dlls?

From "configure" I guess that the following platforms can load, and any
other cannot: all Win32 (incl Cygwin and MinGW), Linux, FreeBSD,
OpenBSD, NetBSD, DEC alpha, Solaris, IRIX, Mac OS X. The others are
nowadays very exotic (e.g. HP-UX), or special (e.g. the iOS support I'm
preparing in a separate patch won't include dll support - Apple does not
permit apps to use shared libraries).

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [Caml-list] dynlink
  2004-04-06  5:58 ` Nicolas Cannasse
@ 2004-04-06  7:46   ` Pietro Abate
  0 siblings, 0 replies; 14+ messages in thread
From: Pietro Abate @ 2004-04-06  7:46 UTC (permalink / raw)
  To: ocaml ml

tnx for your help. below the working code for future reference...

On Tue, Apr 06, 2004 at 07:58:46AM +0200, Nicolas Cannasse wrote:
> (this should work, I have been using 2 years ago)

let modules = Hashtbl.create 17;;
let are_loading = Hashtbl.create 17;;
let load_path = ["."] ;;

let find_in_path path name =
  let filename = (String.uncapitalize name) ^ ".cmo" in
  if not (Filename.is_implicit filename) then
    if Sys.file_exists filename then filename else raise Not_found
  else begin
    let rec try_dir = function
        [] -> raise Not_found
        | dir::rem ->
                let fullname = Filename.concat dir filename in
                if Sys.file_exists fullname then fullname
                else try_dir rem
    in try_dir path
  end

let rec load_module modname =
    try
        Hashtbl.find modules modname
    with
        Not_found ->
            try
                Hashtbl.add modules modname ();
                Hashtbl.add are_loading modname ();
                Printf.printf "Loading: %s\n" modname ;
                Dynlink.loadfile (modname);
		(* register dynamic functions *)
                Hashtbl.remove are_loading modname;
            with Dynlink.Error(Dynlink.Unavailable_unit(depend))
            |Dynlink.Error(
                Dynlink.Linking_error(_,Dynlink.Undefined_global(depend))
                ) as e ->
                        if Hashtbl.mem are_loading depend
                        then failwith ("Crossing with "^depend);
                        load_module (find_in_path load_path depend);
                        Hashtbl.remove modules modname;
                        load_module modname

let _ =
	Dynlink.init();
	load_module (find_in_path load_path "modulename")

p
-- 
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html

-------------------
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] 14+ messages in thread

* Re: [Caml-list] dynlink
  2004-04-06  2:51 [Caml-list] dynlink Pietro Abate
@ 2004-04-06  5:58 ` Nicolas Cannasse
  2004-04-06  7:46   ` Pietro Abate
  0 siblings, 1 reply; 14+ messages in thread
From: Nicolas Cannasse @ 2004-04-06  5:58 UTC (permalink / raw)
  To: Pietro Abate, ocaml ml

> Hi all,
> I'm using dynlink for my project and since now I always had really
> simple dependecies (each module dependes only to an other module).
>
> As things are getting more complicated I need to have one module
> that dependes by many others. My initial solution was to load the
> module, look at possible dependecies error and try to solve them. It
> works well for the simple case but it fails with multiple deps.
>
> Does anyone can show me how to get the list of (recursive) depcs given a
> module ? recursive as a module can depend by an other module that in
> turn dependes by many other ...
>
> something like
>
> let depslist = magicfunction filename in (* I get all recrusive deps or
fail *)
> List.iter (fun f -> Dynlink.loadfile f) (List.rev listdeps) (* I load
eveything in order *)

When loading failed because a dependency is missing , Dynlink is raising an
exception Unavailable_unit "xxx" or Linking_error (_,Undefined_global "xxx")
You can then try to load the corresponding module recursively :

(this should work, I have been using 2 years ago)

let rec load_module modname =
    try
        Hashtbl.find modules modname
    with
        Not_found ->
            try
                Hashtbl.add modules modname ();
                Hashtbl.add are_loading modname ();
                current_module := ("Loading "^modname);
                Dynlink.loadfile (modname^".cmo");
                Hashtbl.remove are_loading modname;
            with
                    Dynlink.Error(Dynlink.Unavailable_unit(depend)) |

Dynlink.Error(Dynlink.Linking_error(_,Dynlink.Undefined_global(depend))) as
e ->
                        if Hashtbl.mem are_loading depend then failwith
("Crossing with "^depend);
                        load_module depend;
                        Hashtbl.remove modules modname;
                        load_module modname

Regards,
Nicolas Cannasse

-------------------
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] 14+ messages in thread

* [Caml-list] dynlink
@ 2004-04-06  2:51 Pietro Abate
  2004-04-06  5:58 ` Nicolas Cannasse
  0 siblings, 1 reply; 14+ messages in thread
From: Pietro Abate @ 2004-04-06  2:51 UTC (permalink / raw)
  To: ocaml ml

Hi all,
I'm using dynlink for my project and since now I always had really
simple dependecies (each module dependes only to an other module).

As things are getting more complicated I need to have one module
that dependes by many others. My initial solution was to load the
module, look at possible dependecies error and try to solve them. It
works well for the simple case but it fails with multiple deps.

Does anyone can show me how to get the list of (recursive) depcs given a
module ? recursive as a module can depend by an other module that in
turn dependes by many other ...

something like

let depslist = magicfunction filename in (* I get all recrusive deps or fail *)
List.iter (fun f -> Dynlink.loadfile f) (List.rev listdeps) (* I load eveything in order *)

tnx,
p

-- 
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html

-------------------
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] 14+ messages in thread

* Re: [Caml-list] Dynlink
  2002-01-07 20:49 [Caml-list] Dynlink Warp
@ 2002-01-08 21:43 ` Warp
  0 siblings, 0 replies; 14+ messages in thread
From: Warp @ 2002-01-08 21:43 UTC (permalink / raw)
  To: OCaml

> I'm trying to dynamicly link a  .cma library which contains externals
> references to a DLL.
> I'm setting (Dynlink.allow_unsafe_modules true) but it keeps me raise :
>
> error while linking mylib.cma.
> The external function '...' is not available.
>
> Although this function is available in the dll, it seems that Dynlink
> doesn't manage to load it.
> How can I do that ( tip : It's for plugin loading, so I don't want to have
> any ref to the DLL into my main build process )

Ok sorry (I fenceposted again :)
I forgot the -dllib flag at compile time.
No more need for answers.

Warp

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Caml-list] Dynlink
@ 2002-01-07 20:49 Warp
  2002-01-08 21:43 ` Warp
  0 siblings, 1 reply; 14+ messages in thread
From: Warp @ 2002-01-07 20:49 UTC (permalink / raw)
  To: OCaml

Hello
I'm trying to dynamicly link a  .cma library which contains externals
references to a DLL.
I'm setting (Dynlink.allow_unsafe_modules true) but it keeps me raise :

error while linking mylib.cma.
The external function '...' is not available.

Although this function is available in the dll, it seems that Dynlink
doesn't manage to load it.
How can I do that ( tip : It's for plugin loading, so I don't want to have
any ref to the DLL into my main build process )

Warp




-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-09-10 16:57 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-09 13:09 [Caml-list] Dynlink Sébastien Hinderer
2015-09-09 13:19 ` Olivier Andrieu
2015-09-09 13:29   ` Sébastien Hinderer
2015-09-09 13:34     ` Xavier Leroy
2015-09-09 13:44       ` Sébastien Hinderer
2015-09-09 16:03         ` Gerd Stolpmann
2015-09-10 12:08           ` Sébastien Hinderer
2015-09-10 16:57             ` Gerd Stolpmann
2015-09-09 13:25 ` Gabriel Scherer
  -- strict thread matches above, loose matches on Subject: below --
2004-04-06  2:51 [Caml-list] dynlink Pietro Abate
2004-04-06  5:58 ` Nicolas Cannasse
2004-04-06  7:46   ` Pietro Abate
2002-01-07 20:49 [Caml-list] Dynlink Warp
2002-01-08 21:43 ` Warp

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).