home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / linux / 25656 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  2.0 KB

  1. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!agate!doc.ic.ac.uk!uknet!edcastle!dcs.ed.ac.uk!sct
  2. From: sct@dcs.ed.ac.uk (Stephen Tweedie)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: gcc 2.3.3 problem
  5. Message-ID: <SCT.93Jan26194220@ascrib.dcs.ed.ac.uk>
  6. Date: 26 Jan 93 19:42:20 GMT
  7. References: <1993Jan25.144702.4734@hp9000.csc.cuhk.hk>
  8. Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
  9. Organization: University of Edinburgh Dept. of Computer Science, Scotland
  10. Lines: 39
  11. In-Reply-To: a080700@hp9000.csc.cuhk.hk's message of 25 Jan 93 14:47:02 GMT
  12.  
  13. In article <1993Jan25.144702.4734@hp9000.csc.cuhk.hk>, a080700@hp9000.csc.cuhk.hk (Stephen Wong S M) writes:
  14. > I use the following command line to compile:-
  15. > gcc -lm -o test_sqrt test_sqrt.c
  16.  
  17. > but I got the following error message:-
  18. > /usr/tmp/cca001331.o: Undefined symbot _sqrt referenced from text segment
  19.  
  20. > Then I tried another command line:-
  21. > gcc -o test_sqrt test_sqrt.c /usr/lib/libm.a
  22.  
  23. > and succeed.
  24.  
  25. > My question is, is it a bug in gcc 2.3.3/lib 4.2 (libm.a), or something
  26. > I misunderstand?
  27.  
  28. This is a feature of most (if not all) unix C compilers.
  29.  
  30. The compiler command (cc or gcc) does not compile your program, but
  31. rather just invokes the preprocessor, compiler and linker as
  32. necessary.  It passess the appropriate command line arguments and
  33. options to each sub-program.
  34.  
  35. However, it uses the position of an option on the command line to
  36. determine which options to pass to which program.  Linking is done
  37. after compilation, so linker options should come after compiler
  38. options and arguments on the gcc command line.
  39.  
  40. Hence, if you have -lm at the start of a gcc command, that option will
  41. never reach the linker, and so the linker cannot locate the symbol
  42. _sqrt from the math library.
  43.  
  44. Placing all the library requests at the end of the gcc command line
  45. will solve the problem; ie, use "gcc -o test_sqrt test_sqrt.c -lm".
  46.  
  47. Cheers,
  48.  Stephen Tweedie.
  49. ---
  50. Stephen Tweedie <sct@uk.ac.ed.dcs>   (Internet: <sct@dcs.ed.ac.uk>)
  51. Department of Computer Science, Edinburgh University, Scotland.
  52.