1

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.

4

2 回答 2

2

D does have link pragmas:

pragma(lib, "dl");

which will cause DMD to emit "-L-ldl" (or the system-appropriate link flag) to the linker. If the linker is order-sensitive (as ld is), you need to specify the pragmas in the order which you manually pass them.

于 2012-08-14T21:56:20.837 回答
1

Just pass -L-ldl.

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

于 2012-08-13T17:52:50.120 回答