Chinaunix首页 | 论坛 | 博客
  • 博客访问: 510731
  • 博文数量: 130
  • 博客积分: 10060
  • 博客等级: 上将
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-21 12:35
文章分类

全部博文(130)

文章存档

2011年(2)

2010年(9)

2009年(41)

2008年(78)

我的朋友

分类: LINUX

2009-10-27 18:21:50

成功从源代码构建libev后,编译文档中的例子也成功,但是运行就报错:Segmentation fault。
后来发现,原来是链接库问题,自己对这方面不熟,也没注意构建libev过程中的重要提示:


Libraries have been installed in:

    /data/www/haifeng.li/mgc/script/scgi/libev/libev/lib


If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following:

    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution

    - add LIBDIR to the `LD_RUN_PATH' environment variable during linking

    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag

    - have your system administrator add LIBDIR to `/etc/ld.so.conf'


See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages.



1.应用构建过程中没有找到库的路径没关系,只要环境变量LD_LIBRARY_PATH中有,运行就没问题;
2.上面的方式对系统设置有依赖,如果构建时环境变量LD_RUN_PATH中有库路径,就把依赖的库的路径写入程序了;
3.构建时不想用上面说的环境变量LD_RUN_PATH也可以,只需要指定选项“-Wl,--rpath -Wl,LIBDIR”就行,不过2的方法比较省事儿;
4.在文件/etc/ld.so.conf中而不是环境变量LD_RUN_PATH中存储库路径,算是2的替代品。

补充:第一种方式也有其他优点,依赖的库的具体路径没写入可执行文件,则可顺利在不同的系统中运行,之需要在LD_LIBRARY_PATH中能找到必须的库。

PS:这两个环境变量的命名。。。
PS2:找到俩链接,比较有用,

Linux平台gcc和动态共享库的基础知识

Linux静态、共享和动态库之编程

当然,如果需要,系统地学习更好。

阅读(2646) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-11-23 15:08:42

不错, 学习了. 碰巧的是, 最近我也在学libev

ttkxu2009-11-05 18:04:32

有点迷糊了

chinaunix网友2009-10-29 12:56:37

emacs字体设置