From: Danny Willems <contact@danny-willems.be>
To: caml-list@inria.fr, Matthew Saffer <m@saffer.me>
Subject: Re: [Caml-list] OCaml-ctypes compilation with library in a different directory
Date: Sun, 31 Jul 2016 15:48:16 +0200 [thread overview]
Message-ID: <60098d65-d997-2d33-bd94-d36bb384c2f5@danny-willems.be> (raw)
In-Reply-To: <b5b9a13b-ba68-37d9-4cf8-8e946108fbb2@danny-willems.be>
[-- Attachment #1: Type: text/plain, Size: 4751 bytes --]
So it resolved by adding -cclib -lbsd after installed it the package
libbsd-dev on Ubuntu. For info, the complete command is:
ocamlfind ocamlopt \
-linkpkg -package ctypes.foreign \
-ccopt -I/usr/local/lib \
-cclib "-Wl,--whole-archive" \
-cclib -lmlx \
-cclib -lbsd \
-cclib "-Wl,--no-whole-archive" \
-cclib "-Wl,-E" \
-cclib -lX11 \
-cclib -lXext \
minilibx.cmx \
hello.ml \
-o hello.native
On 07/31/2016 03:38 PM, Danny Willems wrote:
> 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
>> <mailto: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 <http://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 <http://minilibx.ml>
>> > ```
>> >
>> > Now I wrote a test file named hello.ml <http://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 <http://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
>>
>
[-- Attachment #2: Type: text/html, Size: 8713 bytes --]
prev parent reply other threads:[~2016-07-31 13:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-31 10:22 Danny Willems
2016-07-31 10:34 ` Danny Willems
[not found] ` <CAAefXT_Q217YGCR9=kmiJWT5U47TfYKvt8TD5B0yo+binE52Cg@mail.gmail.com>
2016-07-31 13:38 ` Danny Willems
2016-07-31 13:48 ` Danny Willems [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=60098d65-d997-2d33-bd94-d36bb384c2f5@danny-willems.be \
--to=contact@danny-willems.be \
--cc=caml-list@inria.fr \
--cc=m@saffer.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox