Search code examples
referencehyperlinkddmd

DMD2 (D language) how to link with a c library (libdl.so.2)


Im using Eclipse with the DDT plugin and DMD 2.06 as the compiler. When I try to to use functions like dlopen, dlsym usw I get "unresolved reference" errors, in C and GCC I fixed them by linking with -ldl, -lsdl usw... but the DMD2 compiler doesnt have options like that, is there another way to link with specific libraries?

btw I define the C functions the following way

    extern(C)
    {
        /* From <dlfcn.h>
        *  See http://www.opengroup.org/onlinepubs/007908799/xsh/dlsym.html
        */

        const int RTLD_NOW = 2;

        void *dlopen(const(char)* file, int mode);
        int dlclose(void* handle);
        void *dlsym(void* handle, const(char*) name);
        const(char)* dlerror();
    }

would be happy about any help.


Solution

  • Just pass -L-ldl.

    Also, you don't need to redefine all of these. They are available in the core.sys.posix.dlfcn module.