Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libuv undefined reference to uv_loop_new

Tags:

c

libuv

After compiling, I am trying to run libuv sample program:

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

int main() {
    uv_loop_t *loop = uv_loop_new();

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

    return 0;
}

But, when try to run, I get the following error:

**/tmp/ccHTpspB.o: In function `main':
main.c:(.text+0x9): undefined reference to `uv_loop_new'
main.c:(.text+0x28): undefined reference to `uv_run'
collect2: error: ld returned 1 exit status**

Where did I go wrong ?

PS: It doesn't work with #include "uv.h"

like image 911
Miroslav Trninic Avatar asked Sep 15 '13 19:09

Miroslav Trninic


2 Answers

You need to link the libuv.a with your compiled code and the linker doesn't know where to find the compiled libuv.

To give you a better answer I would need to see you compile command but in the meantime I would strongly recommend this video where Ryan builds a sample libuv project. The actual code he uses is a little out of date as the API has changed but I think you will find the start where he puts a project together very enlightening.

http://vimeo.com/24713213

like image 85
Number 9 Avatar answered Oct 04 '22 01:10

Number 9


In ubuntu I have used following command with success:

gcc sample.c -luv
like image 40
Sandeep Parmar Avatar answered Oct 03 '22 23:10

Sandeep Parmar