English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
External DLL call with mingw OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-09-20 (19:34)
From: Matthieu Dubuget <matthieu.dubuget@g...>
Subject: External DLL call with mingw OCaml

recently, I had to call a third-party DLL (Windows, mingw flavour of OCaml).
It was not easy, because of symbol names decorations (I think).
I'd like to know if there is a more simple way?

Here is the way I found, after asking some questions to internet:

1/ First I had to create a .def file for the third party DLL:
pexports.exe Visa32.dll > visa.def

2/ Then I had to edit the visa.def file, in order to add @nn to symbol 

3/ Import lib generation
dlltool --input-def visa.def --dllname Visa32.dll --output-lib libvisa.a -k

4/ My C-stub, that give access to the functions of Visa32.dll to OCaml
ocamlc -c test_stub.c

Is then turned into a library that depends on Visa32.dll
ocamlmklib -o test_dll -lvisa test_stub.o

5/ Test module compilation
ocamlc -c test.ml
ocamlc -a -o test.cma -dllib dlltest_dll test.cmo

6/ Load test.cma into toplevel

The main problem is that it is a trial error process in order to find 
the @nn to add into visa.def.
I deduce them from the error message I receive (I don't remember if this 
is at step 5/ or 6/) about
visa_function@nn that can't be found.


Matthieu Dubuget