Thread overview | |||||
---|---|---|---|---|---|
|
May 22, 2016 Linking C code with D... | ||||
---|---|---|---|---|
| ||||
While trying to make a benchmark for comparing results of my possible compression replacement, I'm finding it quite difficult to link the c code with the d code. So I've managed to compile the compress.c file using dmc, but when I link the obj file to reference it I don't seem to see it... I've linked a prototype before trying to call it What am I hopelessly doing wrong? unittest { string haystack = "..."; auto f1 = (){ RawBuffer rb; compress(rb, haystack); }; auto f2 = (){ size_t plen; extern (C) char *id_compress(char *id, int idlen, size_t *plen); id_compress(cast(char*) haystack.ptr, haystack.length, &plen); }; auto memoryhungry_compress = benchmark!(f1)(100_000); auto original_compress = benchmark!(f2)(100_000); ... } $ dmd compress_c.obj compress.d -g -O -unittest -main Error 42: Symbol Undefined __D8compress16__unittestL366_5FZ9__lambda2MFZ11id_compressUPaiPkZPa |
May 22, 2016 Re: Linking C code with D... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Era Scarecrow | On 22/05/2016 6:08 PM, Era Scarecrow wrote:
> While trying to make a benchmark for comparing results of my possible
> compression replacement, I'm finding it quite difficult to link the c
> code with the d code.
>
> So I've managed to compile the compress.c file using dmc, but when I
> link the obj file to reference it I don't seem to see it...
>
> I've linked a prototype before trying to call it
>
> What am I hopelessly doing wrong?
> unittest {
> string haystack = "...";
> auto f1 = (){
> RawBuffer rb;
> compress(rb, haystack);
> };
>
> auto f2 = (){
> size_t plen;
> extern (C) char *id_compress(char *id, int idlen, size_t *plen);
> id_compress(cast(char*) haystack.ptr, haystack.length, &plen);
> };
>
> auto memoryhungry_compress = benchmark!(f1)(100_000);
> auto original_compress = benchmark!(f2)(100_000);
> ...
> }
>
> $ dmd compress_c.obj compress.d -g -O -unittest -main
>
> Error 42: Symbol Undefined
> __D8compress16__unittestL366_5FZ9__lambda2MFZ11id_compressUPaiPkZPa
>
Move id_compress out of the unittest block.
|
May 22, 2016 Re: Linking C code with D... | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Sunday, 22 May 2016 at 06:10:07 UTC, rikki cattermole wrote:
> Move id_compress out of the unittest block.
Well that certainly did it...
|
Copyright © 1999-2021 by the D Language Foundation