This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Build a program using a custom glibc
- From: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>
- To: Amittai Aviram <amittai dot aviram at yale dot edu>
- Cc: libc-help at sourceware dot org
- Date: Sat, 26 May 2012 09:40:14 +0530
- Subject: Re: Build a program using a custom glibc
- References: <2844D2FA-E33A-4EC2-BE9E-7DF4C7A006A2@yale.edu>
On 26 May 2012 08:58, Amittai Aviram <amittai.aviram@yale.edu> wrote:
> I have managed to build glibc 2.14 and install it in directory ~/glibc/glibc_install. ?So now I want to build and run programs using this C library instead of my system's default C library. ?First, to be sure that I was using my custom glibc, I added a call to puts into glibc/stdio-common/printf.c:__printf to print a message. ?Then I rebuilt and reinstalled glibc. ?Then I wrote a "Hello, World" program and built (compiled and linked) it as follows:
>
> gcc -nodefaultlibs -static -libgcc -L~/GLIBC/glibc_install/lib -o myprog myprog.c
>
> But I get the following linker error report:
>
> /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
> (.text+0x19): undefined reference to `__libc_csu_init'
> /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
> (.text+0x25): undefined reference to `__libc_start_main'
> /tmp/ccACTQEp.o: In function `main':
> c1.c:(.text+0xa): undefined reference to `puts'
> collect2: ld returned 1 exit status
>
> What am I doing wrong? ?Thanks!
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.
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
--
Siddhesh Poyarekar
http://siddhesh.in