Calling D libraries from C, _deh_beg madness and exception handling

Nicolay Korslund korslund at gmail.com
Mon Oct 29 13:32:34 PDT 2007


Hi, I'm having some problems making a D library and linking it to a C/C++ program. (The library is Monster, http://dsource.org/projects/monster.) I want the library to be as accessible to C++ users as possible, so I want to be able to distribute it as a static library and let users access the library though C function calls. I specifically do NOT want to force users to download a D compiler in order to use the library.

I have created an init() function that initializes the GC and the likes (copied from internal/dmain2), but problems occur when linking - I get undefined references to _deh_beg and _deh_end. Googling around I found that this is a known problem (DMD inserts these symbols when it finds a main() function to set up exception handling), but I couldn't find a solution. I found that defining

void* _deh_beg;
void* _deh_end;

in the C program makes the problem go away, but of course exceptions become horribly broken.

Is there any way to make DMD insert the correct symbols without having a D main? Or can I set them up myself somehow? I don't even know what these pointers are supposed to point to.

N



More information about the Digitalmars-d mailing list