Second shared patch
The patch itself
What is it?
A patch, against OCaml 3.03 ALPHA, making it possible to create,
link against and dynamically load shared libraries on i386 ELF
targets.
Changes
The user will notice 4 new command line options for ocamlopt
compiler, all four only meaningful at the linking stage:
- -shared: output shared library instead of standard executable
- -dynamic: needed if executable will use Natdynlink library
- -noasmrun: do not link against libasmrun.a (does not work currently)
- -nostdlib: do not link against stdlib.cmxa
For the list of source changes look at ChangeLog
What's new compared to first patch
This patch is a bit more involved. Among most important changes is
addition of Natdynlink library. Camlp4(now in OCaml main distribution)
was changed to take advantage of this.
Installation
- mkdir scaml
- cd scaml
- wget OCaml 3.03 ALPHA
- wget patch
- tar xvfz ocaml-3.03-alpha.tar.gz
- cd ocaml-3.03-alpha
- zcat ../2_shared.patch.gz | patch -p1
- ./configure -with -your -favorite -options
- make world bootstrap opt opt.opt install
- iff you plan to LINK AGAINST shared libraries then you will
need CVS version of binutils (in practice
only ld), if however you are only interested in dynamic
loading via Natdynlink library, default ld will most likely
suffice.
You are all set now.
Using it
Following when typed in your shell prompt, will result in creation
of shared library labltk.so. Second command will link tkiface.ml
against this newly created library. (CVS version of
binutils required).
# ocamlopt -shared -o shared.so shared.cmxa -linkall
# ocamlopt -o main shared.so.cmxa main.ml -cclib -Wl,-rpath,.
Or you can play with Camlp4 using the result of this patch
indirectly:
# camlp4.opt pa_r.cms pa_extend.cms q_MLast.cms pr_o.cms revised.ml
Simple example featuring labltk is here
Problems
- Modules loaded with Natdynlink can not be unloaded
- Linking against shared libraries requires CVS
version of binutils
- Unfortunately something goes wrong when CVS
ld links against OCaml 3.03 style shared libraries(C
code linked as .so not the ones made by this patch). Temporary
workaround is there
- The code is not well tested.
- It only works with i386 ELF (In practice i have no means to
test it with anything other than my Linux)
- This patch was prepared in hurry. My machine or OS (i don't
want whom to blame) has become incredibly unstable lately. And
I'm afraid to loose everything.
Feedback
Your comments are welcome. If you have something to
say please do not hesitate, i can be found at
malc@pulsesoft.com (there
were/are DNS problems with above address, so if you have problems, try
av1474@comtv.ru)
Ways to get new ld (4 October 2001 and beyond):
First shared patch
Can be found here
Malcy
Last modified: Thu Nov 1 06:03:24 MSK 2001
Last modified: Wed Oct 1 15:37:15 MSD 2003