Problem with D calling C.
bob at bobcowdery.plus.com
Mon Jan 3 11:52:32 PST 2011
I have a strange problem with D calling C. I have written a small C
wrapper to the speex codec. In my application I was getting a
segmentation fault. Having done some tests if I test my wrapper from a
simple C main it works. If I test it from an equally simple D main it
seg faults. I have lots of other C code in my app which appears to work
fine. I've added the two blocks of calling code below and attached the
wrapper (hope that's allowed). It's all only test code at present so
forgive the mess.
Environment is Ubuntu 10.04, DMD Compiler V 2.050, and GCC for the C code.
extern int lib_speex_init();
extern int lib_speex_term();
extern int lib_speex_get_frame_sz();
extern int lib_speex_encode(short *samples, char*encoded_bytes);
r = lib_speex_encode(smpls, bytes);
printf("Bytes written: %d\n", r);
// In codec.c
extern (C) int lib_speex_init();
extern (C) int lib_speex_resample(short* smpls, int* in_sz, short*
resmpls, int* out_sz);
extern (C) int lib_speex_get_frame_sz();
extern (C) int lib_speex_encode(short *samples, char* encoded_bytes);
int main(char args)
r = lib_speex_encode(cast(short*)smpls, cast(char*)bytes);
writeln("Bytes written: ", r);
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1234 bytes
Desc: not available
More information about the Digitalmars-d-learn