* ocamlopt and *using* DLLs
@ 2005-05-24 3:54 Robert Roessler
2005-05-24 4:29 ` [Caml-list] " Jacques Garrigue
2005-05-24 5:06 ` Nicolas Cannasse
0 siblings, 2 replies; 12+ messages in thread
From: Robert Roessler @ 2005-05-24 3:54 UTC (permalink / raw)
To: Caml-list
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
.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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-24 3:54 ocamlopt and *using* DLLs Robert Roessler
@ 2005-05-24 4:29 ` Jacques Garrigue
2005-05-24 6:39 ` Robert Roessler
2005-05-27 2:13 ` Robert Roessler
2005-05-24 5:06 ` Nicolas Cannasse
1 sibling, 2 replies; 12+ messages in thread
From: Jacques Garrigue @ 2005-05-24 4:29 UTC (permalink / raw)
To: roessler; +Cc: caml-list
From: Robert Roessler <roessler@rftp.com>
> I tried this on the beginners list, but may not have been asking the
> right question(s)... :)
Doesn't look like a beginner question...
> 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
> .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."
Indeed, looking at the sources, .so/.dll is only handled in ocamlc,
not in ocamlopt.
That means that, in ocamlopt, you must either provide a static
library, or use the -cclib option and hope that the system linker does
the right thing. In practice, -cclib ml_scintilla.so should work on
Unix, but the .dll equivalent is not going to work on Windows, as the
linker does not support it.
> 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?
If by stub you mean the ml_scintilla.lib that the windows librarian
builds for you, then you will need it with ocamlopt (but not with
ocamlc).
Of course in both cases you also need an ocaml specific stub library
to wrap calls.
> 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?
Except these linking problems, you can assume identical behaviour.
If there are significant discrepancies, please report them.
Jacques Garrigue
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-24 4:29 ` [Caml-list] " Jacques Garrigue
@ 2005-05-24 6:39 ` Robert Roessler
2005-05-24 7:10 ` Nicolas Cannasse
2005-05-27 2:13 ` Robert Roessler
1 sibling, 1 reply; 12+ messages in thread
From: Robert Roessler @ 2005-05-24 6:39 UTC (permalink / raw)
To: Jacques Garrigue; +Cc: Caml-list
Jacques Garrigue wrote:
> From: Robert Roessler <roessler@rftp.com>
>
>>I tried this on the beginners list, but may not have been asking the
>>right question(s)... :)
>
>
> Doesn't look like a beginner question...
I had been hoping that the ocamlopt manual was not wrong, and that I
was just missing something... simple. :)
>>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?
>
>
> Except these linking problems, you can assume identical behaviour.
> If there are significant discrepancies, please report them.
Actually, it looks like Nicolas brings up a large conceptual
difference... I was at first tempted to say that his points about
ocamlrun.dll did not apply to my case, but then I realized that my
DLL, while primarily concerned with interfacing between OCaml and the
C-land Scintilla editing widget, does in fact call on the OCaml
runtime for things like string and tuple allocation.
Put a different way, ml_scintilla.dll definitely has a dependence on
ocamlrun.dll - which logical need would not go away even if I
repackaged the DLL as a static lib.
So, where (in both a conceptual as well as linking-specific terms) do
I find the hooks (caml_alloc_string, caml_alloc_tuple,
caml_named_value etc) into the OCaml runtime when it is embedded in my
ocamlopt-generated executable?
Robert Roessler
roessler@rftp.com
http://www.rftp.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-24 6:39 ` Robert Roessler
@ 2005-05-24 7:10 ` Nicolas Cannasse
2005-05-27 1:50 ` Robert Roessler
[not found] ` <42967B63.8040408@rftp.com>
0 siblings, 2 replies; 12+ messages in thread
From: Nicolas Cannasse @ 2005-05-24 7:10 UTC (permalink / raw)
To: Robert Roessler, caml-list
> Put a different way, ml_scintilla.dll definitely has a dependence on
> ocamlrun.dll - which logical need would not go away even if I
> repackaged the DLL as a static lib.
Actually the symbols are only imported from ocamlrun.dll if you compile-with
or define the CAML_DLL preprocessor variable.
If you don't have CAML_DLL defined, symbols will be resolved at linking
time, and will then be found in your executable.
So it's possible to have a staticly linked library in both bytecode
(with -custom) and nativecode.
You can have a look at the OCaml Win32 API library Makefile that have
different ways of building and linking it
(http://ocaml-win32.sourceforge.net/).
Nicolas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-24 7:10 ` Nicolas Cannasse
@ 2005-05-27 1:50 ` Robert Roessler
[not found] ` <42967B63.8040408@rftp.com>
1 sibling, 0 replies; 12+ messages in thread
From: Robert Roessler @ 2005-05-27 1:50 UTC (permalink / raw)
To: Caml-list
Nicolas Cannasse wrote:
>>Put a different way, ml_scintilla.dll definitely has a dependence on
>>ocamlrun.dll - which logical need would not go away even if I
>>repackaged the DLL as a static lib.
>
>
> Actually the symbols are only imported from ocamlrun.dll if you compile-with
> or define the CAML_DLL preprocessor variable.
> If you don't have CAML_DLL defined, symbols will be resolved at linking
> time, and will then be found in your executable.
> So it's possible to have a staticly linked library in both bytecode
> (with -custom) and nativecode.
The proper use of CAML_DLL, along with your exposition on the
differences between the bytecode and native runtime models was key to
making this all work for me... but it is now.
> You can have a look at the OCaml Win32 API library Makefile that have
> different ways of building and linking it
> (http://ocaml-win32.sourceforge.net/).
This is actually funny - about a year and a half ago, when I was first
looking at OCaml, I corresponded with Harry Chomsky and pointed out a
bug in the makefile being distributed with this project - having to do
with [not] defining CAML_DLL! :)
I also contributed a small amount of code to the project, but ended up
not being able to use the "OCaml Win32 API" because of the license. :(
Robert Roessler
roessler@rftp.com
http://www.rftp.com
^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <42967B63.8040408@rftp.com>]
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-24 4:29 ` [Caml-list] " Jacques Garrigue
2005-05-24 6:39 ` Robert Roessler
@ 2005-05-27 2:13 ` Robert Roessler
2005-05-27 8:17 ` Anatoly Zaretsky
1 sibling, 1 reply; 12+ messages in thread
From: Robert Roessler @ 2005-05-27 2:13 UTC (permalink / raw)
To: Jacques Garrigue; +Cc: Caml-list
Jacques Garrigue wrote:
> From: Robert Roessler <roessler@rftp.com>
> ...
>>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?
>
>
> Except these linking problems, you can assume identical behaviour.
> If there are significant discrepancies, please report them.
I have a request for an additional [very helpful] export from
dlllablgtk2 which I will detail on the LablGTK list... but in terms of
discrepancies, I only see a minor one:
I notice that the fonts in the editing widget itself as well as in the
surrounding menu and status bars appear differently [in native code]
relative to their appearance in bytecode.
It looks like the same font face and size in each case, but where the
bytecode version seems to be "bold", the native one looks thin and
"spidery". I can supply screenshots, run further tests, whatever
would be helpful if someone wants to look into this.
I have one more issue which I will bring up in this group, since it
presumably effects anyone using GTK apps on Windows: what can I do
about the [gratuitous to me] console window opened with my OCaml/GTK app?
Aside from the philosophical debate about having a "stdout" or not, a
very large number of Windows app certainly manage without one. :)
Did someone on this or the LablGTK list have a piece of code yielding
a tiny/invisible console window for GTK apps on Windows? I thought I
had seen something like that previously, but my searches are coming up
empty.
Robert Roessler
roessler@rftp.com
http://www.rftp.com
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-27 2:13 ` Robert Roessler
@ 2005-05-27 8:17 ` Anatoly Zaretsky
2005-05-28 6:42 ` Nicolas Cannasse
0 siblings, 1 reply; 12+ messages in thread
From: Anatoly Zaretsky @ 2005-05-27 8:17 UTC (permalink / raw)
To: Caml-list
On 5/27/05, Robert Roessler <roessler@rftp.com> wrote:
> ...
> I have one more issue which I will bring up in this group, since it
> presumably effects anyone using GTK apps on Windows: what can I do
> about the [gratuitous to me] console window opened with my OCaml/GTK app?
>
> Aside from the philosophical debate about having a "stdout" or not, a
> very large number of Windows app certainly manage without one. :)
>
> Did someone on this or the LablGTK list have a piece of code yielding
> a tiny/invisible console window for GTK apps on Windows? I thought I
> had seen something like that previously, but my searches are coming up
> empty.
There is a small hack in ocaml-win32 for console window elimination,
mkwinapp (http://cvs.sourceforge.net/viewcvs.py/*checkout*/ocaml-win32/ocaml-win32/mkwinapp.ml)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-27 8:17 ` Anatoly Zaretsky
@ 2005-05-28 6:42 ` Nicolas Cannasse
0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Cannasse @ 2005-05-28 6:42 UTC (permalink / raw)
To: Anatoly Zaretsky, Caml-list
> ...
> I have one more issue which I will bring up in this group, since it
> presumably effects anyone using GTK apps on Windows: what can I do
> about the [gratuitous to me] console window opened with my OCaml/GTK app?
>
> Aside from the philosophical debate about having a "stdout" or not, a
> very large number of Windows app certainly manage without one. :)
>
> Did someone on this or the LablGTK list have a piece of code yielding
> a tiny/invisible console window for GTK apps on Windows? I thought I
> had seen something like that previously, but my searches are coming up
> empty.
> There is a small hack in ocaml-win32 for console window
> elimination, mkwinapp
The other possibility is to call Win32.free_console()
Be careful however, if you try to write to stdout that will raise an
exception.
Nicolas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-24 3:54 ocamlopt and *using* DLLs Robert Roessler
2005-05-24 4:29 ` [Caml-list] " Jacques Garrigue
@ 2005-05-24 5:06 ` Nicolas Cannasse
2005-05-27 1:50 ` Robert Roessler
1 sibling, 1 reply; 12+ messages in thread
From: Nicolas Cannasse @ 2005-05-24 5:06 UTC (permalink / raw)
To: Robert Roessler, caml-list
> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] ocamlopt and *using* DLLs
2005-05-24 5:06 ` Nicolas Cannasse
@ 2005-05-27 1:50 ` Robert Roessler
0 siblings, 0 replies; 12+ messages in thread
From: Robert Roessler @ 2005-05-27 1:50 UTC (permalink / raw)
To: Caml-list
Nicolas Cannasse wrote:
> 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.
Thanks for the explanation of the key difference between the models,
Nicolas!
I have this running just fine now, and it is not really as grim as you
make it sound above. :) Since my DLL really only exists to provide an
interface between OCaml and C-land, I just followed the model used by
LablGTK, and build that interface one of two ways: "dllscintilla.dll"
for bytecode, and "libscintilla.lib" for native.
Robert Roessler
roessler@rftp.com
http://www.rftp.com
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2005-06-02 4:23 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-24 3:54 ocamlopt and *using* DLLs Robert Roessler
2005-05-24 4:29 ` [Caml-list] " Jacques Garrigue
2005-05-24 6:39 ` Robert Roessler
2005-05-24 7:10 ` Nicolas Cannasse
2005-05-27 1:50 ` Robert Roessler
[not found] ` <42967B63.8040408@rftp.com>
[not found] ` <02ce01c56355$14c93db0$19b0e152@warp>
2005-06-01 20:32 ` Robert Roessler
[not found] ` <0d4f01c56702$94853300$0300a8c0@DBLSYG61>
2005-06-02 4:24 ` Robert Roessler
2005-05-27 2:13 ` Robert Roessler
2005-05-27 8:17 ` Anatoly Zaretsky
2005-05-28 6:42 ` Nicolas Cannasse
2005-05-24 5:06 ` Nicolas Cannasse
2005-05-27 1:50 ` Robert Roessler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox