C语言哪些事

检查可执行程序所依赖的库

ldd test

For checking the direct dependencies you should use readelf instead of ldd because ldd also shows the indirect dependencies.

$ readelf -d main | grep library
0x0000000000000001 (NEEDED)             Shared library: [libB.so]
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

ldd also shows the indirect dependencies

$ LD_LIBRARY_PATH=. ldd ./main
linux-vdso.so.1 (0x00007fff13717000)
libB.so => ./libB.so (0x00007fb6738ed000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb6734ea000)
libA.so => ./libA.so (0x00007fb6732e8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb673af0000)

vim /etc/ld.so.conf ,添加动态库搜索路径

include ld.so.conf.d/*.conf
./

加载改配置文件、或者使刚放进指定 lib 目录下的库生效

ldconfig

指针中 的一二

// 声明一个int指针
int *ptr;
// 声明一个int值
int val = 1;
// 为指针分配一个int值的引用
ptr = &val;
// 对指针进行取值,打印存储在指针地址中的内容
int deref = *ptr;
printf("%d\n", deref);

gcc -ldl 选项作用

如果你的程序中使用dlopen、dlsym、dlclose、dlerror 显示加载动态库,需要设置链接选项 -ldl

猜你喜欢

转载自blog.csdn.net/zhixingheyi_tian/article/details/84792407
今日推荐