在Linux中使用不同的glibc库编译C程序 [英] Compile C program in Linux with different glibc library

查看:1191
本文介绍了在Linux中使用不同的glibc库编译C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个防火墙设备基于linux,有glibc-2.3.4,没有gcc编译程序。
当我由另一个linux机器编译程序时,错误消息说:

I have a firewall appliance base on linux that have glibc-2.3.4, and have not gcc to compile a program for that. when I compile a program by another linux machine, error message says:


require glibc.xxx

require glibc.x.x.x

如何在另一个linux机器上为该版本的glibc编译ac程序?

How can I compile a c program in another linux machine for that version of glibc?

推荐答案

一般来说,你必须使用正确的构建环境,其中包含所有目标库和所需的或兼容的版本。 libc变体之间的区别不仅在于链接库名称本身。例如,所需的配置文件可能不同。一些接口可以提供在版本之间变化的报头级内联封包。一般来说,使用较新的库版本运行二进制文件是安全的,但不能使用旧版本。

Generally you have to use the proper building environment which contains all target libraries with the needed or compatible versions. The difference between libc variants is not only in linked library name itself. For example, required configuration files can differ. Some interfaces can be provided with header-level inline wrappers which mutated between versions. It's generally safe to run a binary with a newer library version, but not with an older one.

但是,如果您有一个目标libc的开发包,您的系统中,您可以使用-nostdinc和-nostdlib开关(或显式调用链接器)直接构建二进制文件,并显式指定所需的库。该示例可以从 gcc -v 输出。从我的系统,它是最终的链接器命令:

But, if you have a development package of the target libc installed additionally to your system, you could build a binary directly with it using -nostdinc and -nostdlib switches (or call a linker explicitly), and specifying required libraries explicitly. The example could be got from gcc -v output. From my system, it's final linker command:


/usr/bin/ld --eh-frame-hdr -V -dynamic-linker /libexec/ld-elf.so.1 \
  -o t /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o \
  -L/usr/lib -L/usr/lib /tmp//ccCb5j33.o -lgcc --as-needed -lgcc_s \
  --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed \
  /usr/lib/crtend.o /usr/lib/crtn.o

根据目标libc的具体情况,您应该将这些指令替换为另一些指令。特别是,启动(crt1.o和crti.o),cleanup(crtend.o,crtn.o),libc本身(显式路径而不是-lc)将被替换;可选地,同样应该满足动态链接器。

Depending on target libc specifics, you should replace some of these instructions to another ones. Especially, startup (crt1.o and crti.o), cleanup (crtend.o, crtn.o), the libc itself (explicit path instead of -lc) shall be replaced; optionally, the same should meet dynamic linker.

我看到这是太老问题,但它刚刚重新编辑:)

P.S. I see this is too old question but it has been reedited just now:)

这篇关于在Linux中使用不同的glibc库编译C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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