From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 0B7E97FF37 for ; Sun, 31 Jul 2016 12:35:02 +0200 (CEST) IronPort-PHdr: 9a23:gVkv/BGakn5sG7vCW9RiuZ1GYnF86YWxBRYc798ds5kLTJ75rsWwAkXT6L1XgUPTWs2DsrQf2rKQ7PurAzBIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBybrysXNWD14LojKvop9X6WEZhvHKFe7R8LRG7/036l/I9ps9cEJs30QbDuXBSeu5blitCLFOXmAvgtI/rpMYwuxJ54K16spYcGeWnJ+VrBYBfWT8vNmRw4MzwqTHCSxGO7z0SSDYsnwJMEjTCuT3zWJHg+hT7su5w3TLSacbxS6w9UiiK465tTg6tlyYDMzM86yfdh5ojorhcpUeNrhp50sbrYYWROf9lNvfWetUGTGFddspYUSpQR5y9a48CCvFHN+sO/Nq1nEcHsRbrXVrkP+jo0DId2yf7 Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=contact@danny-willems.be; spf=Pass smtp.mailfrom=contact@danny-willems.be; spf=None smtp.helo=postmaster@3.mo2.mail-out.ovh.net Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of contact@danny-willems.be) identity=pra; client-ip=46.105.58.226; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="contact@danny-willems.be"; x-sender="contact@danny-willems.be"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of contact@danny-willems.be designates 46.105.58.226 as permitted sender) identity=mailfrom; client-ip=46.105.58.226; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="contact@danny-willems.be"; x-sender="contact@danny-willems.be"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@3.mo2.mail-out.ovh.net) identity=helo; client-ip=46.105.58.226; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="contact@danny-willems.be"; x-sender="postmaster@3.mo2.mail-out.ovh.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DrAQAL1J1Xh+I6aS5dhBsqUrsIJIV5AgiBHDwQAQEBAQEBAQERAQEBCA0JCRkvQRABgWAEAwmCHQEFIwQRUQsYAgImAgJXEwgBAYgxCrAOhiaJKQELASSBAYQxgnAIgk2EQEwXgh6CWgWZM1WFQ4sghxqFbIwwg3c1gjERC4FObIU1gk4BAQE X-IPAS-Result: A0DrAQAL1J1Xh+I6aS5dhBsqUrsIJIV5AgiBHDwQAQEBAQEBAQERAQEBCA0JCRkvQRABgWAEAwmCHQEFIwQRUQsYAgImAgJXEwgBAYgxCrAOhiaJKQELASSBAYQxgnAIgk2EQEwXgh6CWgWZM1WFQ4sghxqFbIwwg3c1gjERC4FObIU1gk4BAQE X-IronPort-AV: E=Sophos;i="5.28,449,1464645600"; d="scan'208";a="228537840" Received: from 3.mo2.mail-out.ovh.net ([46.105.58.226]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2016 12:34:54 +0200 Received: from player771.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 05424FF9E05 for ; Sun, 31 Jul 2016 12:34:54 +0200 (CEST) Received: from [192.168.1.40] (LFbn-1-2789-184.w86-252.abo.wanadoo.fr [86.252.217.184]) (Authenticated sender: contact@danny-willems.be) by player771.ha.ovh.net (Postfix) with ESMTPSA id ED68C840075 for ; Sun, 31 Jul 2016 12:34:53 +0200 (CEST) Reply-To: Danny Willems References: To: caml-list@inria.fr From: Danny Willems Message-ID: <8ce14b7d-32ec-0922-8eb5-8adc1e308835@danny-willems.be> Date: Sun, 31 Jul 2016 12:34:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 15297883509296604447 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 50 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeltddrjeefgddvlecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecuogetfeejfedqtdegucdlhedtmd Subject: Re: [Caml-list] OCaml-ctypes compilation with library in a different directory If I use a relative path (for example -cclib -L../minilibx) with ocamlopt, it compiles but I have the same issue when running the binary. On 07/31/2016 12:22 PM, Danny Willems wrote: > Hello, > > I'm writing a binding OCaml to the C library "minilibx", here a mirror > of the library https://github.com/dannywillems/minilibx. > > The Makefile installs the library file libmlx.a in /usr/local/lib and > you have to add the flags -lmlx -lX11 and -lXext to compile. So you > have something like that to compile a test file written in C: > > ``` > gcc -I /usr/local/include -L/usr/local/lib test.c -lmlx -lX11 -lXext > ``` > > I wrote a simple binding to mlx_init, mlx_new_window and mlx_loop in > minilibx.ml: > > ``` > open Ctypes > open Foreign > > type mlx_ptr = unit ptr > type mlx_win = unit ptr > > let mlx_ptr : mlx_ptr typ = ptr void > let mlx_win : mlx_win typ = ptr void > > let mlx_init = > foreign "mlx_init" (void @-> returning mlx_ptr) > > let mlx_new_window = > foreign "mlx_new_window" (mlx_ptr @-> int @-> int @-> string @-> > returning mlx_win) > > let mlx_loop = > foreign "mlx_loop" (mlx_ptr @-> returning void) > ``` > with the corresponding interface in minilibx.mli and compile it with > > ``` > ocamlfind ocamlc -c -package ctypes.foreign -linkpkg minilibx.mli > > ocamlfind ocamlc -c -package ctypes.foreign -linkpkg minilibx.ml > ``` > > Now I wrote a test file named hello.ml > ``` > let () = > let i = Minilibx.mlx_init () in > let w = Minilibx.mlx_new_window i 640 480 "Hello, World" in > Minilibx.mlx_loop i > ``` > > and compile it with > > ``` > ocamlfind ocamlc -o hello -ccopt -L/usr/local/lib -cclib -lmlx -cclib > -lX11 -cclib -lXext minilibx.cmo -package ctypes.foreign -linkpkg > hello.ml > ``` > and when I execute hello, I have > > ``` > Fatal error: exception > Dl.DL_error("/home/dannywillems/.opam/ctypes/lib/stublibs/dllctypes-foreign-base_stubs.so: > undefined symbol: mlx_init") > ``` > > So linking seems not working. But I can't find why. > > If I try to compile in native with ocamlopt (cmo -> cmx), linking is > not done at compile time: > ``` > /usr/bin/ld: cannot find -lmlx > collect2: error: ld returned 1 exit status > File "caml_startup", line 1: > Error: Error during linking > ``` > > Am I using the right option (-ccopt -L/usr/local/lib)? And why ocamlc > doesn't output the error linking message? > > Thank you for you help. > >