linux下使用libevent开发遇到的龌龊问题

时间:2022-03-25 00:13:42

 

按照网上例子搞了个httpd的小demo(linvo_httpd.c),遇到一连串问题,努力google了半天,终于得解,记录之~

 

 

环境:

Linux 2.6.18-164.el5

libevent-1.4.13

 

 

首先用gcc编译时候报了类似下面信息的一堆错

/tmp/ccsKVcym.o: In function `main':

linvo_httpd.c:(.text+0xdf): undefined reference to `event_init'

linvo_httpd.c:(.text+0xf3): undefined reference to `evhttp_start'

应该是找不到编译后的libevent库文件所导致,可能是路径问题

这次在编译时加上了-levent参数后(让其到系统库中找event库),顺利编译通过

gcc -Wall linvo_httpd.c -o linvo_httpd -levent

 

./linvo_httpd 运行之~ 我擦,又来。。。。

./linvo_httpd: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory

依然是路径问题找不到文件

whereis libevent 看下我的libevent默认装到哪里了

libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a

哦~在/usr/local/lib/目录下

 

LD_DEBUG=libs ./linvo_httpd -v 看下demo程序究竟是到哪里去找的该文件 

     32372:     find library=libevent-1.4.so.2 [0]; searching

     32372:      search cache=/etc/ld.so.cache

     32372:      search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib        (system search path)

     32372:       trying file=/lib/tls/i686/sse2/libevent-1.4.so.2

     32372:       trying file=/lib/tls/i686/libevent-1.4.so.2

     32372:       trying file=/lib/tls/sse2/libevent-1.4.so.2

     32372:       trying file=/lib/tls/libevent-1.4.so.2

     32372:       trying file=/lib/i686/sse2/libevent-1.4.so.2

     32372:       trying file=/lib/i686/libevent-1.4.so.2

     32372:       trying file=/lib/sse2/libevent-1.4.so.2

     32372:       trying file=/lib/libevent-1.4.so.2

     32372:       trying file=/usr/lib/tls/i686/sse2/libevent-1.4.so.2

     32372:       trying file=/usr/lib/tls/i686/libevent-1.4.so.2

     32372:       trying file=/usr/lib/tls/sse2/libevent-1.4.so.2

     32372:       trying file=/usr/lib/tls/libevent-1.4.so.2

     32372:       trying file=/usr/lib/i686/sse2/libevent-1.4.so.2

     32372:       trying file=/usr/lib/i686/libevent-1.4.so.2

     32372:       trying file=/usr/lib/sse2/libevent-1.4.so.2

     32372:       trying file=/usr/lib/libevent-1.4.so.2

     32372:

我勒个去~找了这么多地方,就是没到libevent应该在的目录中去找- -!

 

做个链接吧

ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2

 

这下欧了-.-

 

PS:我尝试加上--prefix=/usr/lib/把libevent重新编安装到指定目录,貌似无效。。。。Why???