[ocaml-ctypes] Foreign function interface support

Pavel Zaichenkov zaichenkov at gmail.com
Tue Mar 4 01:54:19 GMT 2014


Hi Anil,

It fails for both OS X and Ubuntu.

Regarding Ubuntu. How would you pass "-Wl,--no-as-needed" to
corebuild? hello (ncurses) example doesn't work on Ubuntu, so this
could be the case. I want to try it also for minisat library, which is
available from the repository.

Although I don't know what is wrong with it in OS X.

Btw, I get "Unbound value returning_checking_errno" error for datetime
example in both systems.

Thanks for your help.


Pavel

On 2 March 2014 13:53, Anil Madhavapeddy <anil at recoil.org> wrote:
> Hi Pavel (CCing the ctypes mailing list as well).
>
> When linking the program, ctypes needs to know how to open the shared
> library.  One way to do this is by specifying the "-lpicosat" in the
> link options, as you've done below.
>
> Unfortunately, the Ubuntu linker has a mode where it decides to not
> link in the library if it's not explicitly referenced in the application,
> so you also need to pass the "-Wl,--no-as-needed" on Ubuntu.
>
> However, before going further, the below link line should have worked
> on MacOS X.  Could you confirm whether it only fails on Ubuntu, or if
> it also doesn't work on MacOS X?
>
> -anil
>
> On 2 Mar 2014, at 07:25, Pavel Zaichenkov <zaichenkov at gmail.com> wrote:
>
>> Hi,
>>
>> I would be very grateful if someone can help me to create OCaml
>> bindings for PicoSAT SAT solver (http://fmv.jku.at/picosat/). I used
>> the version 936 that is available in Ubuntu repository.
>>
>> I started with studying the corresponding chapter in RWC book
>> (https://realworldocaml.org/v1/en/html/foreign-function-interface.html)
>> and came up with the following picosat.ml file (a minimal working
>> example):
>>
>> open Ctypes
>> type picosat = unit ptr
>> let picosat : picosat typ = ptr void
>> open Foreign
>> let init = foreign "picosat_init" (void @-> returning void)
>>
>> This one is a simple program that shouldn't throw an error if binding
>> actually works:
>>
>> open Picosat
>> let _ = init ()
>>
>> The example is compiled using the command from the guide:
>>
>> corebuild -pkg ctypes.foreign -lflags -cclib,lpicosat test.native
>>
>> Command executes successfully, however execution of test.native throws
>> an exception "undefined symbol: picosat_init".
>>
>> I have tried to perform this on two platforms that I need to support:
>> OS X and Ubuntu. I am pretty sure that headers and library itself are
>> installed and are seen in the system path, as I managed to run an
>> example on C using the library. I also checked the library and
>> corresponding symbol names inside the library using "readelf -Ws".
>>
>> Since there is enough evidence that library itself exists and can be
>> successfully linked, I am out of ideas what I miss here and why this
>> binding doesn't work. Are there any suggestions?
>>
>> Thanks.
>>
>>
>> Pavel
>>
>> --
>> You received this message because you are subscribed to the Google Groups "ocaml-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to ocaml-core+unsubscribe at googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
> --
> You received this message because you are subscribed to the Google Groups "ocaml-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ocaml-core+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


More information about the Ctypes mailing list