Chinaunix首页 | 论坛 | 博客
  • 博客访问: 134654
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 247
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-12 22:24
个人简介

学霸

文章分类

全部博文(20)

文章存档

2016年(1)

2015年(11)

2014年(8)

我的朋友

分类: LINUX

2015-07-31 10:34:33

点击(此处)折叠或打开

  1. //source file
  2. main.c p_me.c p_me.h

  3. //get object file
  4. gcc -fPIC -c p_me.c
  5. gcc -c main.c

  6. //get shared library
  7. gcc -shared -o libfun.so p_me.o

  8. //get binary file(can't work rightly)
  9.  gcc -o test -L. -lfun main.o

  10. //exec binary file
  11. ./test
  12. error while loading shared libraries: libfun.so: cannot open shared object file: No such file or directory

  13. //solution 1(search path in link time)
  14. export LD_LIBRARY_PATH=`pwd`
  15. ./test /* work porperly */

  16. //solution 2(not recommended)
  17. gcc -o test /path/libfun.so main.o /* the path is where is your libfun.so at */
  18. ./test /* work porperly */

  19. //solution 3(search path in Run time)
  20. gcc -o test -L. -lfun main.o -Wl,-rpath /path/ /* the path is where is your libfun.so at */
search_so_lib.zip
阅读(3182) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~