Previous Entry Share
How to compile glibc
los angeles, california, bamboo, huntington gardens
davidegrayson
I decided it would be fun to learn how glibc works. My ultimate goal will be to write a "hello world" program in C, for Linux, which does not use glibc.

Anyway, I just succeeded in compiling glibc on Ubuntu 10.04 64-bit. The comments in this shell script explain how I did it:

# Script for building glibc in Ubuntu 10.04 64-bit
# Based on: http://ubuntuforums.org/showthread.php?t=867674

# Prerequisites:
# Create a directory named glibc (or whatever you want).
# Put this script in that directory.
# Put the source of gcc in to a subdirectory named src by running:
#   git clone git://sourceware.org/git/glibc.git src
# Run this script.
# Run:
#   cd build && make
# This will take about an hour and in the end will produce
# a file named libc.so in the build directory.

cd `dirname $0`
PREFIX=`pwd`/install
rm -Rf build
mkdir build
cd build

cat > configparams <<-EOF
	CFLAGS = -pipe -O2 -fstrict-aliasing -g -mno-tls-direct-seg-refs -fno-stack-protector
	BUILD_CFLAGS = -O2 -g
	BASH := /bin/bash
	KSH := /bin/bash
	LIBGD = no
	bindir = /usr/bin
	datadir = /usr/share
	localedir = /usr/lib/locale
	sysconfdir = /etc
	libexecdir = /usr/lib
	rootsbindir = /sbin
	includedir = /usr/include
	docdir = /usr/share/doc
	mandir = /usr/share/man
	sbindir = /usr/sbin
EOF

CC="gcc -fno-stack-protector -U_FORTIFY_SOURCE" CXX="g++ -fno-stack-protector -U_FORTIFY_SOURCE" AUTOCONF=false ../src/configure \
	--host=x86_64-linux-gnu \
	--build=x86_64-linux-gnu \
	--prefix=$PREFIX \
	--without-cvs \
	--enable-add-ons \
	--without-selinux
Tags:

?

Log in