Linking COFF and OMF

%u wfunction at hotmail.com
Tue Mar 1 01:22:32 PST 2011


> what's the error?

I get an access violation at (or sometimes around) the statement

    ModuleInfo* m = _moduleinfo_tlsdtors[i];

inside _moduleTlsDtor() in object_.d.

My entire code for the main file is below (although there's obviously more to the process, like the .obj files,
a few other changes, etc.):

------------------------------------------------------------
import core.stdc.wchar_ : wprintf;
import core.runtime : Runtime;

pragma(lib, "msvcrt.lib");
pragma(startaddress, mainCRTStartup);
extern (C)
{
    //Is this right? What does it even do?
    static __gshared uint _acrtused_con = 0x00009876;
    int main(int argc, char** argv); //in dmain2.d
}

//Just to avoid bringing in Phobos here... unsafe though
void writefln(S...)(in wchar[] format, S args)
{ wprintf(format.ptr, args); wprintf("\n"); }

extern (Windows) int mainCRTStartup()
{
	Runtime.initialize();
	scope(exit) Runtime.terminate(); // << ERROR here
	return main(0, null);
}

int main(string[] args)
{
	writefln("%u", args.length);
	return 0;
}
-------------------------------------------------------------

If I comment out the line with the error, it runs fine *inside* the Visual Studio debugger, but crashes outside
(at a similar place)... can't figure it out, and I think you might need to actually try it to see what I mean.

Any ideas?


More information about the Digitalmars-d mailing list