libevent 小例子一直编译不通过

mac 上通过brew 安装libevent,编译如下代码,但就是一直不通过。

#include <stdio.h>
#include<event.h>
#include<unistd.h>
#include<event2/util.h>
int main(int argc, char const *argv[])
{
    struct event_base* base = event_base_new();
    return 0;
}

报错信息如下:

Undefined symbols for architecture x86_64:
  "_event_base_new", referenced from:
  _main in main-d0e518.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v                                 
to see invocation)


谢谢了!

阅读 6k
1 个回答

编译命令中缺少 libevent 类库,应该像这样

clang  xx.c  -levent
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题