Bravo!

 It works! Blessed be you!

I had tried : (changing the name module to hello.c and of executable to hello - I had seen before a
recommendion not to use "test" as an executable in linux and I am aware of it)


gcc -static -nostdlib hello.c /usr/lib/crt1.o /usr/lib/crti.o \
/usr/lib/crtn.o \
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtbegin.o \
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtend.o \
   -L/usr/lib -lc -lc_nonshared -lgcc -o hello

the build succeeded.

Now I can run  ./hello , and the "hello world" is printed;


As a secondary goal,I am trying to link it without the -static flag ; but this
is of less importance. I will let you know if I succeed.
I saw somewhere that it is not recommeded to linking programs statically to glibc ;
Howevere , for me it is OK to use linking statically since using the new glibc is done only for learning the glibc puropse.


in you're ps mail you said:
according to 'linux from scratch', glibc comes with a test suite. did you
run it at all? did you try to see how it compiles its own test programs?
that probably has a rather complete answer...

I had tried "make check" and as I remeber (It was abour 10 days ago) it was OK. Also I read part of LinuxFromScratch and add some tries according to it.
LinuxFromScratch seems to be for a wider context, really installing everything from scratch.
section 6.12 of it ( Installing Glibc-2.3.2) deals with this.
The bottom line was I had a core dump. It MIGHT been caused because
of the LD_PRELOAD or -Wl,-dynamic-linker flags I had used. But this is less important now.


Thanks!

Regards.
Amir

From: guy keren <[EMAIL PROTECTED]>
To: Amir Binyamini <[EMAIL PROTECTED]>
CC: linux-il@linux.org.il
Subject: Re: A second glibc on Linux
Date: Wed, 30 Mar 2005 01:04:59 +0200 (IST)


On Tue, 29 Mar 2005, Amir Binyamini wrote:

> I do not have , under/usr/lib/gcc-lib/, a crt1.o (also not a symlink to
> /usr/lib).
> So I used the /usr/lib/crt1.o.

this is exactly what i wrote ('strace' told me this short path in its old
twisted way ;)  )

> I use gcc (GCC) 3.2.2on Red Hat 9 ; the new glibc libs I had built is in
> /work/myglibc/lib
> when trying, as I understoof from your suggestion,to compile with
> gcc -static-nostdlib -L/work/myglibc/lib -lc /usr/lib/crt1.o test.c -o
> test
> I got:
> usr/lib/crt1.o(.text+0xc): In function `_start':
> ../sysdeps/i386/elf/start.S:71: undefined reference to `__libc_csu_fini'
> /usr/lib/crt1.o(.text+0x11):../sysdeps/i386/elf/start.S:72: undefined
> reference
> to `__libc_csu_init'
> /usr/lib/crt1.o(.text+0x1d):../sysdeps/i386/elf/start.S:81: undefined
> reference
> to `__libc_start_main'
> collect2: ld returned 1 exit status

ok, this is a start...

> Probing and Googling a bit showed that maybe it should get these symbol from
> libc_nonshared , so I tried
> gcc -static-nostdlib -L/work/myglibc/lib -lc -lc_nonshared /usr/lib/crt1.o
> test.c


ah, getting even better...

> and (strangely) got the same error.

1. never ever ever specify link flags before specifying the list of object
   files. don't ask me why - perhaps this is just a habbit.

2. it looks like there's a need to add '-lgcc' after '-lc_nonshared', gcc
   being libgcc.a found in your compiler's directory.

3. to /usr/lib/crt1.o there's a need to add /usr/lib/crti.o, and for
   /usr/lib/crtn.o   .

4. gcc itself (at least my very old version) also links files named
   'crtbegin.o' and 'crtend.o' - no idea what they are for - perhaps to
   initialize things related to global functoins in libgcc...

and i'm having the easy life - i'm just trying to get gcc -static
--nostdinc to work with the same glibc that i have on my system.

so, give a try(*) with these extras, and see what gives:

gcc -static -nostdlib test.c /usr/lib/crt1.o /usr/lib/crti.o \
    /usr/lib/crtn.o \
    /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o \
    /usr/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o \
    -L/usr/lib -lc -lc_nonshared -lgcc -o test

(*) NOTE: replace /usr/lib/gcc-lib/i386-redhat-linux/2.96 to the matching
          path of the gcc library on your machine.

by the way, you chose a dangerous name, 'test' - i assume you're running
it as './test', to make sure what runs is your binary, and not
/usr/bin/test (i'm writing this mostly for the sake of other readers,
who might try doing your little stun in the future based on a logging of
this thread :0  ).

--
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]


_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]



Reply via email to