libuv undefined reference to uv_loop_new
Asked Answered
A

2

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"

Attitudinarian answered 15/9, 2013 at 19:12 Comment(3)
Do you actually link the library with something like -luv? What's your compiler/linker command?Zante
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"Attitudinarian
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.Attitudinarian
A
8

In ubuntu I have used following command with success:

gcc sample.c -luv
Avouch answered 16/10, 2015 at 17:59 Comment(0)
B
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

Bianca answered 21/9, 2013 at 23:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.