LibEvent的使用过程记录
2015-02-17 16:22
169 查看
The libevent APIprovides 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 alsosupport callbacks due to signals orregular timeouts.(来自官网表述)1从http://libevent.org/下载最新的源码libevent-2.0.22-stable.tar.gz编译;tar -zxvf ./libevent-2.0.22-stable.tar.gzmv libevent-2.0.22-stable ./libevent./configure --prefix=*****makemake install2.编写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 directoryldd ./a.outlinux-vdso.so.1 => (0x00007fff95116000)libevent-2.0.so.5 => not foundlibstdc++.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.5libevent-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 directorycollect2: 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 be searched at LINK TIME for libraries. Thus cc -o foo foo.c -L/usr/local/lib -lfoo means that either libfoo.a or libfoo.so should be found in either /usr/local/lib, or elsewhere in the default search patch (in GNU/Linux, the directories can be listed in /etc/ld.so.conf, and the cache updated by running /etc/ldconfig).
Whether the .a or .so form of the library is needed is platform dependent (e.g., IBM AIX uses only the .a form), and also dependent on compiler options to select dynamic or static linking. The default is normally dynamic linking to save disk space and waste CPU time. However, this means while that the executable foo may have been successfully linked against a shared library, at RUN TIME, the run-time loader looks for it in the default search path, possibly prefixed by a colon-separated list of libraries supplied by the LD_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/lib option).
otice the "(file not found") line. That library is actually present on 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, you need to supply an additional linker option, usually -R or -Wl,-rpath=, with a run-time library path. Our example above becomes for gcc gcc -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
相关文章推荐
- 数据库操作_连接SQL Server数据库示例;连接ACCESS数据库;连接到 Oracle 数据库示例;SqlCommand 执行SQL命令示例;SqlDataReader 读取数据示例;使用DataAdapter填充数据到DataSet;使用DataTable存储数据库表;将数据库数据填充到 XML 文件;10 使用带输入参数的存储过程;11 使用带输入、输出参数的存储过程示;12 获得数据库中表的数目和名称;13 保存图片到SQL Server数据库示例;14 获得插入记录标识号;Exce
- subersion使用过程记录
- mysql 存储过程中 使用变量做表明[学习记录]
- android 最新 NDK r8 在window下开发环境搭建 安装配置与使用 详细图文讲解,完整实际配置过程记录(原创)
- SqlServer存储过程中使用Cursor(游标)操作记录
- 全程记录:今天尝试安装SharePoint Server 2007过程 ,安装成功了,但是开始使用碰到权限问题,应该算是BUg吧
- 使用VS2010编译OpenSSL的过程记录
- [项目过程中所遇到的各种问题记录]编辑器篇——FCKeditor相关知识及各种常见使用问题
- [Metro]使用CSS3+html5+js创建文字颜色渐变(CSS3 Text Gradient) (记录验证过程暂停)
- 使用MySQL存储过程连续插入多条记录
- 使用存储过程中的虚拟表解决同时从几个数据库服务器中读取记录的问题
- 在SqlServer存储过程中使用Cursor(游标)操作记录
- 如何删除一个表中重复的记录? 、、游标,存储过程的使用
- [项目过程中所遇到的各种问题记录]ORM篇——使用NHibernate配置对象实体的一些小问题
- codeStriker(及与svn、bugzilla集成)使用过程记录 续
- [项目过程中所遇到的各种问题记录]编辑器篇——FCKeditor相关知识及各种常见使用问题
- [项目过程中所遇到的各种问题记录]编辑器篇——使用FCKeditor生成静态分页HTML
- 从今天开始记录Ubuntu的使用过程吧
- 对Shanty-Mongo使用过程的一些记录
- [项目过程中所遇到的各种问题记录]编辑器篇——使用FCKeditor生成静态分页HTML