Calling c shared library

simendsjo simendsjo at gmail.com
Fri Mar 23 08:11:13 PDT 2012


On Fri, 23 Mar 2012 15:04:48 +0100, simendsjo <simendsjo at gmail.com> wrote:

> Forgive my programming 101 question :)
>
> I want to call a method from a precompiled shared library:
> // c header
> void f(void);
>
> // my d file
> extern(C) void f();
> void main() {}
>
> $ dmd mydfile.d
> libphobos2.a(deh2_33a_525.o): In function  
> `_D2rt4deh213__eh_finddataFPvZPS2rt4deh213DHandlerTable':
> src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213DHandlerTable+0x4):  
> undefined reference to `_deh_beg'
> src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213DHandlerTable+0xc):  
> undefined reference to `_deh_beg'
> src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213DHandlerTable+0x13):  
> undefined reference to `_deh_end'
> src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213DHandlerTable+0x37):  
> undefined reference to `_deh_end'
> collect2: ld returned 1 exit status
> --- errorlevel 1
>
> Is there a way to do the above, or do I have to manually load the shared  
> library and use alias'es for the functions?

Stupidity has a new name, and it's simendsjo!

I actually had extern(C): at the top of my file, but extern(C) void main()  
was nowhere to be found :)


More information about the Digitalmars-d-learn mailing list