Shared library loading and static constructor

Andre Pany andre at s-e-a-p.de
Fri Mar 22 11:00:32 UTC 2019


On Friday, 22 March 2019 at 10:51:58 UTC, Sobaya wrote:
> I fail to load the shared library created in a specific 
> situation, but I do not know the cause.
>
> ---- a.d
> import b.d
> ----
>
> ---- b.d
> static this() {}
> ----
>
> for above 2 files, I created shared library by following 
> command.
>
> dmd a.d -shared -of=a.so
>
> And I ran below code, but the library is not loaded.
>
> --- main.d
> void main() {
>     import core.runtime;
>     auto lib = Runtime.loadLibrary(a.so)
>     assert(lib !is null);
> }
> ---
>
> Please tell me why. Thanks.

As far as I know different to windows, linus will not search 
current working directory for a.so. if this is the issue here, 
you have different possibilities. You could determine the current 
working directory and use std.path: buildPath to create an 
absolute path to a.so.
This path you can then use for Runtime.loadLibrary.

Or you can set the environment variable LD_LIBRARY_PATH.

I do not know what is the correct way on linux.

Kind regards
Andre


More information about the Digitalmars-d-learn mailing list