Build a program using a custom glibc

Paul Pluzhnikov ppluzhnikov@google.com
Sat May 26 03:39:00 GMT 2012


On Fri, May 25, 2012 at 8:28 PM, 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!

Libc also has startup files, crt*.o, which must match the libc you are using.

Go into your glibc build directory, and do "make check". Note the
command line that is being used to link tests. Replicate that command
line (adjusting for your ~/GLIBC/glibc_install/lib installation).

Also note that your command line currently is *completely* bogus:
-llibgcc asks the linker to look for liblibgcc.{a,so}; perhaps you
meant '-lc' to link with libc?

The order of libraries and sources on the command line matters:
http://webpages.charter.net/ppluzhnikov/linker.html

Finally, "-L~/..." will not be expanded by the shell. Try '-L ~/...'
or '-L$HOME/...' instead.

Hope this helps.

-- 
Paul Pluzhnikov



More information about the Libc-help mailing list