libuv undefined reference to uv_loop_new

放肆的年华 提交于 2019-12-04 03:31:27

问题


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"


回答1:


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




回答2:


In ubuntu I have used following command with success:

gcc sample.c -luv


来源:https://stackoverflow.com/questions/18816428/libuv-undefined-reference-to-uv-loop-new

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!