Compile for old-kernel Linux

Firstly, we need the suitable Glibc version

My target Linux with kernel-2.6.9, and my host is Kernel-2.6.32, so I can use Glibc version 2.12.1

Infomation from the project Readme :

When working with Linux kernels, the GNU C Library version from

version 2.4 on is intended primarily for use with Linux kernel version

2.6.0 and later. 
 

 

 

wget http://ftp.gnu.org/gnu/libc/glibc-2.12.1.tar.bz2

tar -xjf glibc-2.12.1.tar.bz2

mkdir glibc-2.12.1-build

cd glibc-2.12.1-build/

../glibc-2.12.1/configure --prefix=/usr/local/glibc-2.12.1 --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --enable-kernel=2.6.0 --enable-static-nss

You need add the --enable-static-nss option otherwise you may get the following Warnning when compile your program with this glibc:

warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Error1:

 

/home/kimi/soft/glibc-2.12.1-build/libc.a(nsswitch.o):(.data+0x8): undefined reference to `_nss_files_getaliasent_r'

/home/kimi/soft/glibc-2.12.1-build/libc.a(nsswitch.o):(.data+0x18): undefined reference to `_nss_files_endaliasent'
/home/kimi/soft/glibc-2.12.1-build/libc.a(nsswitch.o):(.data+0x28): undefined reference to `_nss_files_setaliasent'
/home/kimi/soft/glibc-2.12.1-build/libc.a(nsswitch.o):(.data+0x38): undefined reference to `_nss_files_getaliasbyname_r'

....

It's a common bug since glic-2.3 version,a patchcan fix it 

patch -p1 < ../patchfile

 

make -j4

make install

 

 

Secondly, Use -static Option

gcc hello.c -o hello -L/usr/local/glibc-2.12.1/lib  -static -nostdlib  /usr/local/glibc-2.12.1/lib/crt1.o /usr/local/glibc-2.12.1/lib/crti.o -lm -lc -lgcc -lgcc_eh  -lc  /usr/local/glibc-2.12.1/lib/crtn.o

 

Reference

http://stackoverflow.com/questions/8961622/how-to-port-c-c-applications-to-legacy-linux-kernel-versions

http://blog.csdn.net/force_eagle/article/details/6758045

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值