This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -lsocket patch
- To: Craig Burley <burley at gnu dot org>, d dot love at dl dot ac dot uk
- Subject: Re: -lsocket patch
- From: Robert Lipe <robertl at dgii dot com>
- Date: Wed, 8 Jul 1998 12:36:14 -0500
- Cc: egcs at cygnus dot com
- References: <rzqemvx5oiz.fsf@djlvig.dl.ac.uk> <199807072349.TAA01179@melange.gnu.org>
Craig Burley wrote:
> Dave, have you verified that this patch actually works vis-a-vis building
> u77-test on an SCO system?
Dave may not have seen it work on an SCO system, but I have. It does
pass u77-test on OpenServer now, but as you suspect, I think we're
"getting away" with something.
> Reason I ask is, I'd expect the user who needs -lsocket will, when
> using g77's libU77 HOSTNM() intrinsic, have to specify
>
> -lg2c -lsocket -lm
>
> or similar to get it to work. That is, I think the g77 driver will
> *append* -lg2c -lm to the command line, rather than recognizing
> that -lsocket is a library upon which -lg2c might depend. So the
> command `g77 foo.f -lsocket' would become `g77 foo.f -lsocket -lg2c -lm',
> which would cause -lsocket to be skipped because, at that point,
> there's no unresolved reference to gethostname(). That is, if I
> have my UNIX library user-punishment algorithm right. :)
You've left element of randomness out of the heurstic. :-) Your
understanding matches mine for static linking. Dynamic linkers will
defer that until runtime.
I deleted all of the testsuite but the attached code called '/tmp/t.f'.
(robertl) rjlhome:/play/negcs/gcc
$ ./g77 -B./ -L ../i686*/libf2c /tmp/t.f
Undefined first referenced
symbol in file
gethostname ../i686-pc-sco3.2v5.0.5/libf2c/libg2c.a(hostnm_.o)
a.out: fatal error: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
(robertl) rjlhome:/play/negcs/gcc
$ ./g77 -B./ -L ../i686*/libf2c /tmp/t.f -lsocket
(robertl) rjlhome:/play/negcs/gcc
$ ./a.out
Host name is rjlhome.dgii.com
If I add a '-v' and look at the link line, I see:
./collect2 -b elf -Ra,XPG4PLUS,ELF -YP,/usr/ccs/lib:/lib:/usr/lib -Qn /usr/ccs/lib/crt1.o /usr/ccs/lib/values-Xa.o ./crtbegin.o -L ../i686-pc-sco3.2v5.0.5/libf2c -L. -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib /usr/tmp/cckg1Vw8%O -lsocket -lg2c -lm -lgcc -lcrypt -lgen -lc -lgcc ./crtend.o /usr/ccs/lib/crtn.o
I see it fail exactly as you describe building staticly, but not dynamically
which is the default.
$ ./g77 -static -B./ -L ../i686*/libf2c /tmp/t.f -lsocket
Undefined first referenced
symbol in file
gethostname ../i686-pc-sco3.2v5.0.5/libf2c/libg2c.a(hostnm_.o)
a.out: fatal error: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
$ ./g77 -B./ -L ../i686*/libf2c /tmp/t.f -lsocket
(robertl) rjlhome:/play/negcs/gcc
$ ldd a.out
dynamic linker: a.out: file loaded: /usr/lib/libsocket.so.1
dynamic linker: a.out: file loaded: /usr/lib/libc.so.1
So you're right. On systems that staticly link things, this would fail
for the reasons you describe. This would presumably include OpenServer
in COFF mode but that currently fails on g77 for the lack of multilibs.
Test case.
integer i
intrinsic hostnm
external lenstr
integer lenstr
character wd*100
i=hostnm(wd)
if(i.ne.0) then
call perror ('*** hostnm')
else
write (6,*) 'Host name is ', wd(:lenstr(wd))
end if
end
integer function lenstr (str)
C return length of STR not including trailing blanks, but always
C return >0
character *(*) str
if (str.eq.' ') then
lenstr=1
else
lenstr = lnblnk (str)
end if
end