LibEvent的使用过程记录
来源:互联网 发布:小型公司java项目实例 编辑:程序博客网 时间:2024/06/02 07:30
The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.(来自官网表述)
1从http://libevent.org/下载最新的源码libevent-2.0.22-stable.tar.gz编译;
tar -zxvf ./libevent-2.0.22-stable.tar.gz
mv libevent-2.0.22-stable ./libevent
./configure --prefix=*****
make
make install
2.编写demo测试 略
g++ ./libevent.cpp -g -O0 -levent -L /usr/local/lib
./a.out: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
ldd ./a.out
linux-vdso.so.1 => (0x00007fff95116000)
libevent-2.0.so.5 => not found
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x000000363b000000)
libm.so.6 => /lib64/libm.so.6 (0x0000003638800000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000363ac00000)
libc.so.6 => /lib64/libc.so.6 (0x0000003638c00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003638400000)
libevent-2.0.so.5 没有找到
查看位置
whereis libevent-2.0.so.5
libevent-2.0.so: /usr/local/lib/libevent-2.0.so.5
[root@chenfeng test]# g++ ./libevent.cpp -o libevent -g -O0 -levent -L/usr/local/lib -Wl,rpath=/usr/local/lib
/usr/bin/ld: rpath=/usr/local/lib: No such file: No such file or directory
collect2: ld 返回 1
来自http://gcc.gnu.org/ml/gcc-help/2005-12/msg00017.html
The -L option supplies a colon-separated library path that is to besearched at LINK TIME for libraries. Thuscc -o foo foo.c -L/usr/local/lib -lfoomeans that either libfoo.a or libfoo.so should be found in either/usr/local/lib, or elsewhere in the default search patch (inGNU/Linux, the directories can be listed in /etc/ld.so.conf, and thecache updated by running /etc/ldconfig).
Whether the .a or .so form of the library is needed is platformdependent (e.g., IBM AIX uses only the .a form), and also dependent oncompiler options to select dynamic or static linking. The default isnormally dynamic linking to save disk space and waste CPU time.However, this means while that the executable foo may have beensuccessfully linked against a shared library, at RUN TIME, therun-time loader looks for it in the default search path, possiblyprefixed by a colon-separated list of libraries supplied by theLD_LIBRARY_PATH variable.If, in our example, /usr/local/lib is not part of the default path,then the run-time loader will not be able to find the shared library,EVEN THOUGH LINKING SUCCEEDED (because of the -L/usr/local/liboption).
otice the "(file not found") line. That library is actually presenton that system in /usr/local/lib, and I can make it succeed like this:% env -i LD_LIBRARY_PATH=/usr/local/lib ldd /usr/local/bin/emacs libXaw3d.so.5 => /usr/local/lib/libXaw3d.so.5 libXmu.so.4 => /usr/lib/libXmu.so.4...Thus, when shared libraries are present in nondefault directories, youneed to supply an additional linker option, usually -R or -Wl,-rpath=,with a run-time library path. Our example above becomes for gccgcc -o foo foo.c -L/usr/local/lib -lfoo -Wl,-rpath=/usr/local/lib
In a Makefile, I would write this asgcc -o foo foo.c -L$(prefix)/lib -lfoo -Wl,-rpath=$(prefix)/lib
[root@chenfeng test]# g++ ./libevent.cpp -o livevent -g -O0 -L/usr/local/lib -levent -Wl,-rpath=/usr/local/lib[root@chenfeng test]# ./livevent
编译通过
OK
- LibEvent的使用过程记录
- libevent的使用
- libevent的使用(socket)
- libevent的使用
- libevent的使用(socket)
- libevent的使用
- 测试libevent的使用
- http libevent的使用
- libevent的使用
- Libevent的使用
- 记录使用svn的过程
- Libevent监听事件的建立过程
- libevent 在windows下的编译过程
- libevent 在windows下的编译过程
- libevent的使用(socket)
- vs2010下libevent的使用
- vs2010下libevent的使用
- vs2010下libevent的使用
- 100行Android代码自定义一个流式布局-FlowLayout
- 高效使用Eclipse
- 做10年Windows程序员与做10年Linux程序员的区别
- NIO客户机服务器通信示例
- 字典树 HDU-1251 统计难题
- LibEvent的使用过程记录
- ZJNU——1262电灯泡(三分题)
- [CODEVS 1173] 最优贸易
- Codeforces Round #291 (Div. 2) Han Solo and Lazer Gun
- 找个教程开撸linux与win7双系统的作死之旅
- Wakelocks: Detect No-Sleep Issues in Android* Applications(转载)
- C++-指针详解(2)
- MySQL数据库MyISAM和InnoDB存储引擎的比较
- POJ 1321----棋盘问题(深搜)