home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / linux / 25578 < prev    next >
Encoding:
Text File  |  1993-01-27  |  2.1 KB  |  49 lines

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