6

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"

nmaier
  • 32,336
  • 5
  • 63
  • 78
Miroslav Trninic
  • 3,327
  • 4
  • 28
  • 51
  • Do you actually link the library with something like `-luv`? What's your compiler/linker command? – nmaier Sep 15 '13 at 19:22
  • I included -luv option and now command is gcc -o main main.c -luv But now I get "error while loading shared libraries libuv.so.11" – Miroslav Trninic Sep 15 '13 at 22:01
  • Hi; Sorry,I forgot to answer. Solution is in the Number 9-s post below: I just had to link libuv together with my compiled code, and everything works fine. I have to mention that libuv api is changing quickly, and Ryan Dahl-s video is based on old api. – Miroslav Trninic Oct 24 '13 at 10:45

2 Answers2

7

In ubuntu I have used following command with success:

gcc sample.c -luv
brodoll
  • 1,851
  • 5
  • 22
  • 25
6

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

Number 9
  • 615
  • 3
  • 9