minix3下安装libevent

短命女 2023-01-13 01:36 231阅读 0赞
  1. libevent是一个c语言编写的事件框架,支持异步IO、定时器、信号事件。它支持跨平台,大部分都是在linux下安装并使用,今天介绍在unix系统minix3上的安装。
  2. minix3上编译环境是clang,clang++,并不是我们常见的gcc,g++,所以在进行源码编译的时候,需要指定系统编译器。再一个就是minix3上没有/usr/local这个目录,如果直接configure安装不指定libevent安装前缀prefix,那么它就会安装到/usr/local目录下,这个目录并不是系统设定的,所以它的包含文件,库目录文件不会被系统搜索到,最后在使用libevent库的时候,需要我们手动添加include dir,lib dir,为了减少不必要的麻烦,我们指定configure时的前缀prefix为/usr,这样,libevent的头文件会安装到/usr/include下,而依赖库文件会安装到/usr/lib目录下。
  3. 编译安装过程:
  4. 1、下载libevent,这里官网是[https://libevent.org/][https_libevent.org],下载地址是:[https://github.com/libevent/libevent/releases/download/release-2.1.10-stable/libevent-2.1.10-stable.tar.gz][https_github.com_libevent_libevent_releases_download_release-2.1.10-stable_libevent-2.1.10-stable.tar.gz]。
  5. 2、解压
  6. 3configuremake make install安装三步曲。
  7. 这里进行configure的时候,需要注意,因为minix3.3.0版本没有gcc,g++,但是有clang,我们需要指定clangc compiler,所以在configure的时候需要指定CC=/usr/pkg/bin/clang,我的这个机器本来已经安装了openssl,但是却找不到openssl.pc文件,所以提示没有找到openssl依赖库,只好禁用openssl,使用命令--disable-openssl
  8. ./configure --prefix=/usr CC=/usr/pkg/bin/clang --disable-openssl
  9. 这一步没有报错,就可以进行下面的编译和安装了
  10. #make
  11. #make install
  12. 下面的打印信息是我 make install的打印信息:
  13. # make install
  14. make install-am
  15. ./install-sh -c -d '/usr/bin'
  16. /usr/bin/install -c event_rpcgen.py '/usr/bin'
  17. ./install-sh -c -d '/usr/lib'
  18. /bin/sh ./libtool --mode=install /usr/bin/install -c libevent.la libevent_core.la libevent_extra.la libevent_pthreads.la '/usr/lib'
  19. libtool: install: /usr/bin/install -c .libs/libevent.lai /usr/lib/libevent.la
  20. libtool: install: /usr/bin/install -c .libs/libevent_core.lai /usr/lib/libevent_core.la
  21. libtool: install: /usr/bin/install -c .libs/libevent_extra.lai /usr/lib/libevent_extra.la
  22. libtool: install: /usr/bin/install -c .libs/libevent_pthreads.lai /usr/lib/libevent_pthreads.la
  23. libtool: install: /usr/bin/install -c .libs/libevent.a /usr/lib/libevent.a
  24. libtool: install: chmod 644 /usr/lib/libevent.a
  25. libtool: install: ranlib /usr/lib/libevent.a
  26. libtool: install: /usr/bin/install -c .libs/libevent_core.a /usr/lib/libevent_core.a
  27. libtool: install: chmod 644 /usr/lib/libevent_core.a
  28. libtool: install: ranlib /usr/lib/libevent_core.a
  29. libtool: install: /usr/bin/install -c .libs/libevent_extra.a /usr/lib/libevent_extra.a
  30. libtool: install: chmod 644 /usr/lib/libevent_extra.a
  31. libtool: install: ranlib /usr/lib/libevent_extra.a
  32. libtool: install: /usr/bin/install -c .libs/libevent_pthreads.a /usr/lib/libevent_pthreads.a
  33. libtool: install: chmod 644 /usr/lib/libevent_pthreads.a
  34. libtool: install: ranlib /usr/lib/libevent_pthreads.a
  35. ./install-sh -c -d '/usr/include'
  36. /usr/bin/install -c -m 644 include/evdns.h include/event.h include/evhttp.h
  37. include/evrpc.h include/evutil.h '/usr/include'
  38. ./install-sh -c -d '/usr/include/event2'
  39. /usr/bin/install -c -m 644 include/event2/buffer.h include/event2/buffer_compat.h
  40. include/event2/bufferevent.h include/event2/bufferevent_compat.h
  41. include/event2/bufferevent_ssl.h include/event2/bufferevent_struct.h include/event2/dns.h
  42. include/event2/dns_compat.h include/event2/dns_struct.h include/event2/event.h
  43. include/event2/event_compat.h include/event2/event_struct.h include/event2/http.h
  44. include/event2/http_compat.h include/event2/http_struct.h include/event2/keyvalq_struct.h
  45. include/event2/listener.h include/event2/rpc.h include/event2/rpc_compat.h
  46. include/event2/rpc_struct.h include/event2/tag.h include/event2/tag_compat.h
  47. include/event2/thread.h include/event2/util.h include/event2/visibility.h
  48. '/usr/include/event2'
  49. ./install-sh -c -d '/usr/include/event2'
  50. /usr/bin/install -c -m 644 include/event2/event-config.h '/usr/include/event2'
  51. ./install-sh -c -d '/usr/lib/pkgconfig'
  52. /usr/bin/install -c -m 644 libevent.pc libevent_core.pc libevent_extra.pc libevent_pthreads.pc '/usr/lib/pkgconfig'
  53. 从中可以看出头文件全部加入了/usr/include目录,库文件加入了/usr/lib目录,这样系统就能找到他们的位置了。
  54. 可以编写一个定时器来测试一下:

hello.c

  1. #include <stdio.h>
  2. #include <event.h>
  3. #include <time.h>
  4. struct event ev;
  5. struct timeval tv;
  6. void timer_cb(int fd, short event, void *arg)
  7. {
  8. printf("timer_cb\n");
  9. event_add(&ev, &tv);
  10. }
  11. int main()
  12. {
  13. struct event_base *base = event_init();
  14. tv.tv_sec = 1;
  15. tv.tv_usec = 0;
  16. event_set(&ev, -1, 0, timer_cb, NULL);
  17. event_base_set(base, &ev);
  18. event_add(&ev, &tv);
  19. event_base_dispatch(base);
  20. return 0;
  21. }
  22. 编译:这里就需要手动设定依赖库
  23. #clang -o hello hello.c -levent

编译运行打印信息:

  1. # clang -o hello hello.c
  2. /var/tmp/hello-2fbefe.o: In function `timer_cb':
  3. hello.c:(.text+0x43): undefined reference to `event_add'
  4. /var/tmp/hello-2fbefe.o: In function `main':
  5. hello.c:(.text+0x81): undefined reference to `event_init'
  6. hello.c:(.text+0xcc): undefined reference to `event_set'
  7. hello.c:(.text+0xe1): undefined reference to `event_base_set'
  8. hello.c:(.text+0xfc): undefined reference to `event_add'
  9. hello.c:(.text+0x10a): undefined reference to `event_base_dispatch'
  10. clang: error: linker command failed with exit code 1 (use -v to see invocation)
  11. # clang -o hello hello.c -levent
  12. # ./hello
  13. timer_cb
  14. timer_cb
  15. timer_cb
  16. timer_cb
  17. ^C
  18. #
  19. 不设定依赖库,编译报错;若编译通过直接运行,控制台会间隔1秒打印timer\_cb。

发表评论

表情:
评论列表 (有 0 条评论,231人围观)

还没有评论,来说两句吧...

相关阅读

    相关 minix3安装libevent

        libevent是一个c语言编写的事件框架,支持异步IO、定时器、信号事件。它支持跨平台,大部分都是在linux下安装并使用,今天介绍在unix系统minix3上的安装

    相关 vmware安装minix并开启x11

        最近突然想弄一下minix这个老牌的系统。     vmware安装minix3虚拟机,其实很简单的:     1、新建虚拟机,选择经典。     2、选择客户机