July 12th, 2011

los angeles, california, bamboo, huntington gardens

How to compile glibc

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`
rm -Rf build
mkdir build
cd build

cat > configparams <<-EOF
	CFLAGS = -pipe -O2 -fstrict-aliasing -g -mno-tls-direct-seg-refs -fno-stack-protector
	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

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 \
  • Current Music
    Pete Fountain
  • Tags