www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Calling c shared library

reply simendsjo <simendsjo gmail.com> writes:
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_finddataFPvZPS2rt4deh21
DHandlerTable+0x4):  
undefined reference to `_deh_beg'
src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh21
DHandlerTable+0xc):  
undefined reference to `_deh_beg'
src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213
HandlerTable+0x13):  
undefined reference to `_deh_end'
src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213
HandlerTable+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?
Mar 23 2012
parent simendsjo <simendsjo gmail.com> writes:
On Fri, 23 Mar 2012 15:04:48 +0100, simendsjo <simendsjo 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_finddataFPvZPS2rt4deh21
DHandlerTable+0x4):  
 undefined reference to `_deh_beg'
 src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh21
DHandlerTable+0xc):  
 undefined reference to `_deh_beg'
 src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213
HandlerTable+0x13):  
 undefined reference to `_deh_end'
 src/rt/deh2.d:(.text._D2rt4deh213__eh_finddataFPvZPS2rt4deh213
HandlerTable+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 :)
Mar 23 2012