davidegrayson (davidegrayson) wrote,

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 \
Tags: glibc

  • Full Width Unicode Characters

    I found these characters in Brawl Stage files: Safety Boxes Boxes that save! The letters above are the unicode "full width" versions of our…

  • Window Smashers

    This three minute video is a great civics lesson and will teach you everything you need to know about any government: (see Anderson's full story…

  • Values

    I've been having a good debate with some friends about my alternative to universal healthcare. Two of them have raised broader philosophical…

  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.