3

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.x.x.x

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

Majid
  • 13,853
  • 15
  • 77
  • 113
hamSh
  • 1,163
  • 1
  • 13
  • 27
  • [There is a similar question](http://stackoverflow.com/questions/2071325/relink-a-shared-library-to-a-different-version-of-libc). – Sadeq Aug 15 '10 at 21:53

2 Answers2

2

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.

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

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:)

Netch
  • 4,171
  • 1
  • 19
  • 31
1

The apbuild-apgcc tool sets things up to link against older versions of the glibc symbols.

caf
  • 233,326
  • 40
  • 323
  • 462
  • this is very good answer, but i want to use inotify that it is in kernel 2.6.13 and later, but with apgcc i can,t use that. – hamSh Aug 16 '10 at 07:09