Shared library: loading doesn't call shared static this

yazd yazan.dabain at gmail.com
Sat Dec 7 12:20:03 PST 2013


On Saturday, 7 December 2013 at 20:11:15 UTC, Mathias LANG wrote:
> Hello,
> I'm in the process of creating a PAM module using D.
>
> First step, I ported <pam/modules.h> and the included 
> pam/_types.h> to D, pretty straightforward.
> Then I created a simple D source, which looks like:
>
> ````
> extern(C) int  pam_sm_open_session(pam_handle_t* pamh, int 
> flags, int ac, const char** av)
> {
>     writeln(__PRETTY_FUNCTION__);
>     return PAM_SUCCESS;
> }
> ````
>
> Compiled it using dub, set up PAM & all the required stuff 
> (I've already wrote one in C so it was pretty easy), and ran my 
> test util, written in C.
> I got a SIGSEGV.
> I tracked it down to be the writeln call, it seems the fd are 
> not initialized.
> Easy way to fix it is to call std_stdio_static_this() from 
> std.stdiobase.
>
> So I went to http://dlang.org/dll-linux.html , copied the 
> example, and here's my result:
>
> xxxx at xxxx:~/Work/PAM$ ./main
> +main()
> Dynamic library is loaded
> dll() function is found
> dll()
> unloading libdll.so
> -main()
>
> Which differs from the example in that the "shared static this" 
> are not called.
> Is that a bug ?
>
> NB: DMD 2.064.2, debian x86_64, gcc 4.8.2

I believe you'll need to call rt_init() to initialize the d 
runtime.
That will most probably fix the issues you're seeing.

http://dlang.org/phobos/core_runtime.html#.rt_init


More information about the Digitalmars-d-learn mailing list