Using dlopen/dlsym

Benjiro via Digitalmars-d digitalmars-d at puremagic.com
Mon Dec 26 16:39:19 PST 2016


On Tuesday, 27 December 2016 at 00:05:39 UTC, Andrei Alexandrescu 
wrote:
> Consider this code:
>
> ===========
> import core.sys.posix.dlfcn;
> extern(C) void fun() {}
> void main()
> {
>     fun();
>     void *hndl = dlopen(null, RTLD_LAZY);
>     if (!hndl) assert(0);
>     auto p = dlsym(hndl, "fun".ptr);
>     if (!p)
>     {
>         import core.stdc.stdio;
>         printf("%s\n", dlerror());
>     }
> }
> ===========
>
> It works (i.e. outputs nothing) on http://dpaste.dzfl.pl and on 
> Vladimir's machine.
>
> On my Mint and Ubuntu machines it outputs:
>
> ./test: undefined symbol: fun
>
> I'm building with no flags using dmd. What could be the problem 
> here?
>
>
> Thanks,
>
> Adnrei

Odd ... Works perfect on Debian ( DMD64 D Compiler v2.071.2 ).


More information about the Digitalmars-d mailing list