C binding with D function

llaine via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 3 08:56:34 PDT 2016


On Wednesday, 3 August 2016 at 15:47:48 UTC, bachmeier wrote:
> On Wednesday, 3 August 2016 at 15:24:56 UTC, llaine wrote:
>> On Wednesday, 3 August 2016 at 15:14:24 UTC, Kagamin wrote:
>>> On Wednesday, 3 August 2016 at 15:08:51 UTC, llaine wrote:
>>>> So basically I have to create wrapper.c ?
>>>
>>> Yes, but you should write it in D. Runtime initialization is 
>>> at https://dlang.org/phobos/core_runtime.html#.Runtime
>>
>
> // No main
> // compile as libffi-example.so
>
> Then in Ruby:
>
> module Example
>     extend DL::Importable
>     dlload "./libffi-example.so"
>     extern "void example_init()"
>     extern "void example_exit()"
>     extern "void foo(int)"
> end
>
> Example.example_init
> Example.foo(3)
> Example.example_exit

Okay on stack overflow, they are not using ffi but dl.
I tried changing ffi to dl, it's the same don't work unfortunatly.




More information about the Digitalmars-d-learn mailing list