如何链接到不同的 libc 文件? [英] How to link to a different libc file?

查看:23
本文介绍了如何链接到不同的 libc 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于版本差异,我想与我的程序一起提供共享库,而不是使用目标系统的.

I want to supply the shared libraries along with my program rather than using the target system's due to version differences.

ldd 说我的程序使用了这些共享库:

ldd says my program uses these shared libs:

linux-gate.so.1 =>  (0xf7ef0000)**(made by kernel)**  
libc.so.6 => /lib32/libc.so.6 (0xf7d88000)**(libc-2.7.so)**  
/lib/ld-linux.so.2 (0xf7ef1000)**(ld-2.7.so)**

我已经通过编译成功链接了 ld-xxx.so:

I have successfully linked ld-xxx.so by compiling with:

gcc -std=c99 -D_POSIX_C_SOURCE=200112L -O2 -m32 -s -Wl,-dynamic-linker,ld-2.7.so myprogram.c

但是我没有成功链接libc-xxx.so.我该怎么做?

But I have not managed to successful link libc-xxx.so. How can I do that ?

推荐答案

我找到了怎么做:

rpath 指定提供的库的位置.此文件夹应包含:libc.so.6libdl.so.2libgcc_s.so.1 甚至更多.使用 strace 检查您的二进制文件使用了哪些库.

rpath specifies where the provided libraries are located. This folder should contain: libc.so.6, libdl.so.2, libgcc_s.so.1 and maybe more. Check with strace to find out which libraries your binary file uses.

ld.so 是提供的链接器

gcc -Xlinker -rpath=/default/path/to/libraries -Xlinker -I/default/path/to/libraries/ld.so program.c

这篇关于如何链接到不同的 libc 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆