centos学习:动态链接库 .so "dll"?

一 、生成linux动态链接库

gcc -o libme.so age.c -shared

二、调用动态链接库

[root@localhost study]# gcc -L /root/study -l me daichen.c -o daichen
[root@localhost study]# ls
age.c  age.h  daichen  daichen.c  libme.so  makefile
[root@localhost study]# ./daichen
./daichen: error while loading shared libraries: libme.so: cannot open shared object file: No such file or directory
[root@localhost study]# 
gcc -L /root/ -l me daichen.c -o daichen

三、查询该程序有什么依赖

ldd daichen

四、出现错误 动态链接库连接不上

[root@localhost study]# ./daichen
./daichen: error while loading shared libraries: libme.so: cannot open shared object file: No such file or directory

失败原因是操作系统无法找到libme.so

linux和windows一样 有类似system32的系统库文件夹。各种公共类库都放在这个地方

centos中有个和windows很类似的两个存放公共库的文件夹

/lib 内核级
/usr/lib 用户系统级
/usr/lib64/ 64为系统才有

[root@localhost study]# cp libme.so /lib
[root@localhost study]# ./daichen
./daichen: error while loading shared libraries: libme.so: cannot open shared object file: No such file or directory
[root@localhost study]# ldconfig
[root@localhost study]# ./daichen
is 0x400758 
is 0x400759 
is 0x40075a 
is 0x40075b 
is 0x40075c 
is 0x40075d 
is 0x40075e 
[root@localhost study]# 

ldconfig:更新动态缓存库

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值