Q: how to get C code to work in D?

Hoenir mrmocool at gmx.de
Tue Jun 12 13:53:00 PDT 2007


BCS schrieb:
> Reply to Hoenir,
> 
>> BCS schrieb:
>>
>>> Reply to Hoenir,
>>>
>>>> I got a C file (it's a library, so in C you would create a static
>>>> library and link it to another program) I want to use in D.
>>>> I already created the necessary d file as described here:
>>>> http://www.digitalmars.com/d/interfaceToC.html
>>>> But how do I link the C code? dmd isn't able to compile C files.
>>>> I know how to get a dll working (creating C dll, corresponding lib
>>>> with
>>>> implib and then adding that lib to the command line of dmd) but I
>>>> want
>>>> it to be statically linked like in C.
>>>> Any hints?
>>> Download dmc (the digital mars C compiler) and build the lib with
>>> that. Then pass the .obj's or .lib to dmd with everything else. Or
>>> use link.exe directly.
>>>
>> I don't know which switches to use to generate a static library with
>> dmc.
>> I tried
>> dmc -c main.c
>> dmd test.d main.obj
>> which didn't fix the Symbol Undefined error.
> 
> could you post a short example?
> 
> 
Ah, I'm so dumb. I forgot to pass the other d module to dmd that is 
imported by test.d


More information about the Digitalmars-d-learn mailing list