home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!inmos!fulcrum!bham!warwick!pipex!pavo.csi.cam.ac.uk!news
- From: ijackson@nyx.cs.du.edu (Ian Jackson)
- Subject: Re: gcc 2.3.3 problem
- Message-ID: <1993Jan27.123423.28432@infodev.cam.ac.uk>
- Sender: iwj@cam-orl.co.uk (Ian Jackson)
- Nntp-Posting-Host: leek.cam-orl.co.uk
- Reply-To: ijackson@nyx.cs.du.edu (Ian Jackson)
- Organization: Olivetti Research Ltd
- References: <1993Jan25.144702.4734@hp9000.csc.cuhk.hk> <SCT.93Jan26194220@ascrib.dcs.ed.ac.uk>
- Date: Wed, 27 Jan 1993 12:34:23 GMT
- Lines: 35
-
- >In article <1993Jan25.144702.4734@hp9000.csc.cuhk.hk>, a080700@hp9000.csc.cuhk.hk (Stephen Wong S M) writes:
- >> I use the following command line to compile:-
- >> gcc -lm -o test_sqrt test_sqrt.c
- >
- >> but I got the following error message:-
- >> /usr/tmp/cca001331.o: Undefined symbot _sqrt referenced from text segment
- >
- >> gcc -o test_sqrt test_sqrt.c /usr/lib/libm.a
- [...]
-
- In article <SCT.93Jan26194220@ascrib.dcs.ed.ac.uk> sct@dcs.ed.ac.uk
- (Stephen Tweedie) writes:
- [...]
- >Hence, if you have -lm at the start of a gcc command, that option will
- >never reach the linker, and so the linker cannot locate the symbol
- >_sqrt from the math library.
- >
- >Placing all the library requests at the end of the gcc command line
- >will solve the problem; ie, use "gcc -o test_sqrt test_sqrt.c -lm".
-
- Steve is right about the fix but wrong about the reason. Using gcc -v
- will show that the -lm does get passed through to the linker.
-
- Specifying -lm is exactly the same as writing /usr/lib/libm.a at that
- place on the command line. However linking with a library only
- extracts those parts of the library which supply definitions for
- symbols which have been used but not yet defined. _sqrt hasn't been
- used yet, as it is in test_sqrt.c (ie cca001331.o in the quote above)
- which the linker hasn't seen at that point.
-
- --
- Ian Jackson iwj@cam-orl.co.uk ..!uknet!cam-orl!iwj These opinions are my own.
- Olivetti Research Ltd, Old Addenbrookes Site, Trumpington St, Cambridge, UK;
- Home: 35 Molewood Close, Cambridge, CB4 3SR; +44 223 327029. +44 223 343398
- Email also via: ijackson@nyx.cs.du.edu PGP2 public key available on request
-