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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 707EE7FF37 for ; Sun, 31 Jul 2016 15:38:53 +0200 (CEST) IronPort-PHdr: 9a23:rTk0UBHL4Jzw/zWmqzznFZ1GYnF86YWxBRYc798ds5kLTJ75r8qwAkXT6L1XgUPTWs2DsrQf2rKQ7PurBzxIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBybrysXNWD14LojKvsq9X6WEZhvHKFe7R8LRG7/036l/I9ps9cEJs30QbDuXBSeu5blitCLFOXmAvgtI/rpMYwuxJrpuk5+sVcfaL/dqU+BfwEXXV1e1wysejiqQXDQBTH3XISXGgM2k5NKxPM4h/3RNH0v32+/uF03S3fOcztUZg1Xy6j5uFlUkzGkiACYhIw9mfGwvNxiKZWpQnp8xd4xZLda529OPN4eLKYYtIeQWdERYBbWnoSUcuHc4ITAr9Zbq5jpI7nqg5S/BY= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=contact@danny-willems.be; spf=Pass smtp.mailfrom=contact@danny-willems.be; spf=None smtp.helo=postmaster@6.mo2.mail-out.ovh.net Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of contact@danny-willems.be) identity=pra; client-ip=87.98.165.38; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="contact@danny-willems.be"; x-sender="contact@danny-willems.be"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of contact@danny-willems.be designates 87.98.165.38 as permitted sender) identity=mailfrom; client-ip=87.98.165.38; receiver=mail3-smtp-sop.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 (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@6.mo2.mail-out.ovh.net) identity=helo; client-ip=87.98.165.38; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="contact@danny-willems.be"; x-sender="postmaster@6.mo2.mail-out.ovh.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D7AAAZ/51XhyalYlddhBsqUgGnQZNGJIV5AoEkPBABAQEBAQEBAREBAQEKCwkJGS+CMgQDgiYBBSMERxsLDgoNGgMCAkUBEQYBDAYCAQEOiAUDGwqwM4suA4QeAQEBBwEBAQEBIoUygnCCVYRMgnWCWgWGWQySTlWFQ4sghxqFbIwwg3c1gjERC4FObIgDAQEB X-IPAS-Result: A0D7AAAZ/51XhyalYlddhBsqUgGnQZNGJIV5AoEkPBABAQEBAQEBAREBAQEKCwkJGS+CMgQDgiYBBSMERxsLDgoNGgMCAkUBEQYBDAYCAQEOiAUDGwqwM4suA4QeAQEBBwEBAQEBIoUygnCCVYRMgnWCWgWGWQySTlWFQ4sghxqFbIwwg3c1gjERC4FObIgDAQEB X-IronPort-AV: E=Sophos;i="5.28,450,1464645600"; d="scan'208,217";a="186478640" Received: from 6.mo2.mail-out.ovh.net ([87.98.165.38]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jul 2016 15:38:51 +0200 Received: from player771.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id 36053FFA523 for ; Sun, 31 Jul 2016 15:38:51 +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 09F08840065; Sun, 31 Jul 2016 15:38:50 +0200 (CEST) To: Matthew Saffer , caml-list@inria.fr References: <8ce14b7d-32ec-0922-8eb5-8adc1e308835@danny-willems.be> From: Danny Willems Message-ID: Date: Sun, 31 Jul 2016 15:38:49 +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: multipart/alternative; boundary="------------F48D81BF7A8AE846400B07EA" X-Ovh-Tracer-Id: 18404804304201196831 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 49 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeltddrjeefgdeikecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecuogfuuhhsphgvtghtffhomhgrihhnucdlgeelmd Subject: Re: [Caml-list] OCaml-ctypes compilation with library in a different directory This is a multi-part message in MIME format. --------------F48D81BF7A8AE846400B07EA Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I found this post on GitHub: https://github.com/ocamllabs/ocaml-ctypes/issues/236 I added the arguments to pass to ld and the mlx_init error disappear (now I've an error about strlcpy used by minilibx which is not defined on Linux). So my command is ``` ocamlfind ocamlopt \ -linkpkg -package ctypes.foreign \ -ccopt -I/usr/local/lib \ -cclib "-Wl,--whole-archive" \ -cclib -lmlx \ -cclib "-Wl,--no-whole-archive" \ -cclib "-Wl,-E" \ -cclib -lX11 \ -cclib -lXext \ minilibx.cmx \ hello.ml \ -o hello.native ``` On 07/31/2016 03:27 PM, Matthew Saffer wrote: > > If ld can't find the library, don't you need to change your LD_LOAD_PATH? > > On Sun, Jul 31, 2016, 06:35 Danny Willems > wrote: > > 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. > > > > > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --------------F48D81BF7A8AE846400B07EA Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
I found this post on GitHub: https://github.com/ocamllabs/ocaml-ctypes/issues/236
I added the arguments to pass to ld and the mlx_init error disappear (now I've an error about strlcpy used by minilibx which is not defined on Linux).

So my command is
```
ocamlfind ocamlopt  \
  -linkpkg -package ctypes.foreign \
  -ccopt -I/usr/local/lib \
  -cclib "-Wl,--whole-archive" \
  -cclib -lmlx  \
  -cclib "-Wl,--no-whole-archive" \
  -cclib "-Wl,-E" \
  -cclib -lX11 \
  -cclib -lXext \
  minilibx.cmx \
  hello.ml \
  -o hello.native
```

On 07/31/2016 03:27 PM, Matthew Saffer wrote:

If ld can't find the library, don't you need to change your LD_LOAD_PATH?

On Sun, Jul 31, 2016, 06:35 Danny Willems <contact@danny-willems.be> wrote:
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.
>
>


--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--------------F48D81BF7A8AE846400B07EA--