link errors when using extern (C) structs

DanielG simpletangent at gmail.com
Sun Oct 28 03:28:20 UTC 2018


I'm wrapping a C library which has a lot of structs defined, and 
I keep running into issues where dmd complains that .init isn't 
defined ("Symbol Undefined __xxxxxxx__initZ" etc).

I'm struggling to narrow it down to a simple example that 
demonstrates it - I actually made something that's kind of 
minimal, but it goes from working to breaking depending on 
whether the file extension is .di or .d, for the file containing 
the extern (C)'ed struct definitions. Also it seems to depend (in 
the .di case) on whether the C structs use double vs. int values 
for their fields. (int fields work with either file extension)

But simply changing the file extension in my real project, of the 
header files translated by dstep, seems to have no effect.

In short, it seems that for certain C structs I cannot use them 
as a field in a D struct even with a manually-specified default 
value - I get link errors no matter what (init/toHash/opEquals). 
How can I get around that?

Am I supposed to be doing something with C structs to avoid these 
kinds of errors in my D code? I've searched the forum but nothing 
really jumps out at me as relevant.


More information about the Digitalmars-d-learn mailing list