Search code examples
dlibuv

Linking against libuv


I wanted to try using libuv in dlang. I downloaded the dlang bindings like this:

git clone [email protected]:tamediadigital/libuv.git

Now what I do next to get my "hello world" running?

I tried this:

ldc2 hello.d -luv

But it said:

ldc2: Unknown command line argument '-luv'.  Try: 'ldc2 -help'
ldc2: Did you mean '-v'?

I think I need to tell the compiler where the library bindings are located. And then import something in the source code, probably with import libuv;?

Here is the 'hello world' code I want to "port" to D:

#include <stdio.h>
#include <stdlib.h>
#include <uv.h>

int main() {
    uv_loop_t *loop = malloc(sizeof(uv_loop_t));
    uv_loop_init(loop);

    printf("Now quitting.\n");
    uv_run(loop, UV_RUN_DEFAULT);

    uv_loop_close(loop);
    free(loop);
    return 0;
}

Here is the bindings github page: https://github.com/tamediadigital/libuv

Library home page: http://www.libuv.org


Solution

  • First that was a wrong bindings, here are the good ones: https://github.com/changloong/libuv

    Assuming you did git [email protected]:changloong/libuv.git in current dir.

    Compile:

    ldc2 hello.d -I=libuv/deimos/libuv/ -I=libuv/ -L=-luv
    

    The source:

    import uv;
    import core.memory;
    import std.stdio;
    
    int main(){
        uv_loop_t *loop = new uv_loop_t;
        uv_loop_init(loop);
    
        printf("Now quitting.\n");
        uv_run(loop, uv_run_mode.UV_RUN_DEFAULT);
    
        uv_loop_close(loop);
        return 0;
    }
    

    Hope it helps someone to get started with using C libs in D.