On 2013-05-23 06:27, Ellery Newcomer wrote:
In the context of shared libraries, with gcc__attribute__((constructor)) void myfunc() { .. } is used to make myfunc be called upon loading of the shared library (you can tell I know what I am talking about here) via some field in the ELF headers, apparently. Is there any way to get our trusty d compilers to do the equivalent? Sure, Ellery, we have this awesome feature called module constructors. Check em out. Ehh, I would be using this to initialize druntime... You could just define _init, couldn't you? Yes, but there is only one _init, while the above can be used with multiple functions and thus wouldn't inadvertently cause important code to not run. If I don't have to, I'd rather not. Wait, why are you initializing druntime? Because druntime isn't set up to do it yet for c main calling d shared lib. You'd think it would need the same sort of functionality when it does implement it, though.
I don't know if it's automatically linked but here you go: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dylib_fixes.c -- /Jacob Carlborg
