免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 9548 | 回复: 4
打印 上一主题 下一主题

Linux动态库多重依赖,编译问题!!!!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-06-02 23:17 |只看该作者 |倒序浏览

①libb.so依赖liba.so;
②程序A依赖libb.bso;
编译程序A的时候为什么要指定liba.so啊?
有回避方法么?

① gcc -fPIC -shared -o libtest01.so test01.c
②gcc -fPIC -shared -o libtest02.so test02.c
③gcc -o test main.c -L./ -I./ -ltest02 -ltest01

不指定libtest01库,通不过诶…………

有没有一种方法,可以不指定libtest01.so这个库的啊?

论坛徽章:
0
2 [报告]
发表于 2012-06-09 20:56 |只看该作者
楼主你这样生成的libtest02依赖关系似乎不太对
ldd libtest02.so 结果会看不到libtest01.so
②gcc -fPIC -shared -o libtest02.so test02.c -L./ -I./ -ltest01

这样libtest02的依赖关系才正确

③就不用指定libtest01了

论坛徽章:
0
3 [报告]
发表于 2012-06-10 15:59 |只看该作者
回复 2# janetliu9

即使按你的说法做了,上层应用程序不指定libtest01,也是不行的诶。


[root@localhost test]# gcc -fPIC -shared -o libtest02.so test02.c -L./ -I./ -ltest01
[root@localhost test]# gcc -o test main.c -L. -I. -ltest02
/usr/bin/ld: warning: libtest01.so, needed by ./libtest02.so, not found (try using -rpath or -rpath-link)
./libtest02.so: undefined reference to `funtion1'
collect2: ld returned 1 exit status
[root@localhost test]# gcc -o test main.c -L. -I. -ltest02 -ltest01
[root@localhost test]#


[root@localhost test]# ldd test
        linux-gate.so.1 =>  (0x00eff000)
      ★  libtest02.so => not found
      ★  libtest01.so => not found
        libc.so.6 => /lib/libc.so.6 (0x00b91000)
        /lib/ld-linux.so.2 (0x00b6b000)



[root@localhost test]# ldd libtest02.so
        linux-gate.so.1 =>  (0x00fa5000)
      ★  libtest01.so => not found
        libc.so.6 => /lib/libc.so.6 (0x0087f000)
        /lib/ld-linux.so.2 (0x00b6b000)

编译libtest02.so的时候,依赖库确实不对,可是还是无法解决问题诶。o(╯□╰)o
[root@localhost test]# gcc -fPIC -shared -o libtest02.so test02.c -L./ -I./
[root@localhost test]# ldd libtest02.so
        linux-gate.so.1 =>  (0x00afc000)
        libc.so.6 => /lib/libc.so.6 (0x00301000)
        /lib/ld-linux.so.2 (0x00b6b000)
    ★ 应该依赖libtest01.so的,但是没有加入进来

论坛徽章:
0
4 [报告]
发表于 2012-06-11 17:01 |只看该作者
不是有出错信息吗
因为libtest01.so  不在缺省的库搜索路径里

export LD_LIBRARY_PATH=$LD_LIBRARY_PATHPWD 或者 gcc -Wl,-rpath-link $PWD -Wl,-rpath $PWD -o test main.c -L. -I. -ltest02

论坛徽章:
0
5 [报告]
发表于 2015-09-29 17:05 |只看该作者
这是链接时出的错误,@janetliu9,你的方法时解决运行时刻找不到库。
Linux中动态库依赖动态库,必须在编译可执行程序时把这些动态库加入到编译选项中。和windows不太一样。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP