From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id D0B4EBBAF for ; Sun, 20 Sep 2009 21:34:58 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ai0CAFYgtkrRVdvfkGdsb2JhbACRRYh0PwEBAQEJCQwHEwOiRoExjW8BAwIEhBcFgVg X-IronPort-AV: E=Sophos;i="4.44,419,1249250400"; d="scan'208";a="46927555" Received: from mail-ew0-f223.google.com ([209.85.219.223]) by mail4-smtp-sop.national.inria.fr with ESMTP; 20 Sep 2009 21:34:58 +0200 Received: by ewy23 with SMTP id 23so2524672ewy.26 for ; Sun, 20 Sep 2009 12:34:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:content-type :content-transfer-encoding; bh=sO9p6I/6VYayUzuZAY9U8qcY2yR9lDqobxoHwlDy5KY=; b=Jvea0twQDjSbq9CBjRjH6O3ZBZLnrSVcT0gmrafjSG2OsTOu8zoDd5SDYGWwSn2JY4 ShGTSCUcIrUr2ZmMWbiIeoah5UvhIqrMzyO/oP8WEE4JNsiGv9IEotd70fudKgTfybQs CRzZEpkXXiVx7KHP5EjuGqELzO5EnUHrXzi34= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; b=B4fpgQhejr+vHF/OOtycb/K6k2TFgww7cjBpCfJR/PPuXbzQ/D0lMpwESQuizLBvof WJRv/uJNMSx2SEhCTq+GO/OvB7jWg16fEEZo1NfjEtLHQ4pcvVqhS6qSRWxTApDrVQmY smUU2wSXYxMQx1YPWXQQQb0oGkgR9oBFHgoHI= Received: by 10.211.129.20 with SMTP id g20mr1993950ebn.14.1253475298054; Sun, 20 Sep 2009 12:34:58 -0700 (PDT) Received: from ?192.168.1.20? (43.14.197-77.rev.gaoland.net [77.197.14.43]) by mx.google.com with ESMTPS id 28sm290904eyg.17.2009.09.20.12.34.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 20 Sep 2009 12:34:57 -0700 (PDT) Message-ID: <4AB683DF.7000206@gmail.com> Date: Sun, 20 Sep 2009 21:34:55 +0200 From: Matthieu Dubuget User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: caml-list@inria.fr Subject: External DLL call with mingw OCaml Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; matthieu:01 dubuget:01 matthieu:01 dubuget:01 mingw:01 ocaml:01 mingw:01 ocaml:01 def:01 def:01 lib:01 --dllname:01 ocamlc:01 stub:01 ocamlmklib:01 Hello, 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 names. 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. Salutations Matthieu Dubuget