This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Build a program using a custom glibc


On May 26, 2012, at 12:10 AM, Siddhesh Poyarekar wrote:

> You can do the compile and link separately. And for the linker, you
> provide the crt*.o files from ~/GLIBC/glibc_install/lib.
> 
> Try running the gcc command with a -v and you'll see what the linker
> gets called with. You can then use the same command with your paths
> adjusted to use your glibc.
> 

Thank you very much for this suggestion, and thanks very much to Paul Pluzhnikov for his somewhat similar suggestion of using the command line of "make check" as a template.  With some further work, I've arrived at a solution, represented by the sample makefile below.  In this one, I assume that you have a program called "prog" that you want to build from source "prog.c" and that you have installed your custom glibc in directory "/home/my_acct/glibc_install."

TARGET = prog
OBJ = $(TARGET).o
SRC = $(TARGET).c
CC = gcc
CFLAGS = -g
LDFLAGS = -nostdlib -nostartfiles -static
GLIBCDIR = /home/my_acct/glibc_install/lib
STARTFILES = $(GLIBCDIR)/crt1.o $(GLIBCDIR)/crti.o `gcc --print-file-name=crtbegin.o`
ENDFILES = `gcc --print-file-name=crtend.o` $(GLIBCDIR)/crtn.o
LIBGROUP = -Wl,--start-group $(GLIBCDIR)/libc.a -lgcc -lgcc_eh -Wl,--end-group

$(TARGET): $(OBJ)
        $(CC) $(LDFLAGS) -o $@ $(STARTFILES) $^ $(LIBGROUP) $(ENDFILES) 
$(OBJ): $(SRC)
        $(CC) $(CFLAGS) -c $^

> Once you get this working, it would be great if you could add this to
> the glibc wiki in the tips and tricks section:
> 
> http://sourceware.org/glibc/wiki


I would be glad and honored to do so, but I could not find an "edit" link on the Wiki, and it says at the top right, just below the "Home Page" tab, "Immutable Page."  Is there a way that I can contribute this to the Wiki Tips and Tricks section?  Thanks!

Best wishes,
Amittai

Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@yale.edu
http://www.amittai.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]