Version française
Home     About     Download     Resources     Contact us    
Browse thread
ocamlopt and *using* DLLs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] ocamlopt and *using* DLLs
> I tried this on the beginners list, but may not have been asking the
> right question(s)... :)
>
> 1) Can DLLs appear as input to the ocamlopt compiler like they can
> with ocamlc?  The manual says "yes": "Arguments ending in .o, .a or y
> .so (.obj, .lib and .dll under Windows) are assumed to be C object
> files and libraries. They are linked with the program."
>
> I get "ocamlopt.opt: don't know what to do with ml_scintilla.dll."
>
> 2) If DLLs can in fact be used with ocamlopt, is the model the same as
> with ocamlc?  In particular,
>
> 2a) can I use them *without* stub libraries?
>
> 2b) can I in general expect that an app that works well with ocamlc
> and a collection of OCaml cma libs and compiled DLLs (LablGTK and
> associated runtime) will work with ocamlopt - assuming that I generate
> and replace cmo/cma files with cmx/cmxa files?
>
> Robert Roessler
> roessler@rftp.com
> http://www.rftp.com

I was not maybe clear enough on the beginner list :)
The main problem is that your DLL need to call Ocaml API, which it is linked
with.

In bytecode there is no problem since the whole API is inside ocamlrun.dll
so your DLL and ocamlrun.exe will simply use this API dll together.
In native compilation however there is no more ocamlrun.dll, since the API
is staticly linked into your executable. That means that your DLL that was
working in bytecode will load ocamlrun.dll and call it while your executable
is calling staticly linked API. This will result quite quickly in a crash
since ocamlrun.dll is not initialized correctly.

The only possible way to get the DLL working is to patch it so it loads its
API inside your.exe and not inside ocamlrun.dll. But then you will need a
different version of the DLL for each application (!). It would be nice if
OCaml could provide the equivalent of ocamlrun.dll for the native
compilation mode.

Nicolas Cannasse