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

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!matt.ksu.ksu.edu!news
  2. From: probreak@matt.ksu.ksu.edu (James Michael Chacon)
  3. Newsgroups: comp.os.linux
  4. Subject: Re: gcc 2.3.3 problem
  5. Date: 26 Jan 1993 06:36:43 -0600
  6. Organization: Kansas State University
  7. Lines: 40
  8. Message-ID: <1k3b8rINN7o9@matt.ksu.ksu.edu>
  9. References: <1993Jan25.144702.4734@hp9000.csc.cuhk.hk>
  10. NNTP-Posting-Host: matt.ksu.ksu.edu
  11.  
  12. a080700@hp9000.csc.cuhk.hk (Stephen Wong S M) writes:
  13.  
  14. >I'm using linux 0.99pl4/SLS 1.0/gcc 2.3.3/lib 4.2 and I test the
  15. >gcc compiler with the following program:-
  16.  
  17. >test_sqrt.c
  18. >#include <math.h>
  19. >#include <stdio.h>
  20. >main()
  21. >{   double a;
  22. >    a = 2;
  23. >    printf("square root of 2 is %f\n", sqrt(a));
  24. >}
  25.  
  26. >I use the following command line to compile:-
  27. >gcc -lm -o test_sqrt test_sqrt.c
  28.  
  29. >but I got the following error message:-
  30. >/usr/tmp/cca001331.o: Undefined symbot _sqrt referenced from text segment
  31.  
  32. >Then I tried another command line:-
  33. >gcc -o test_sqrt test_sqrt.c /usr/lib/libm.a
  34.  
  35. >and succeed.
  36.  
  37. >My question is, is it a bug in gcc 2.3.3/lib 4.2 (libm.a), or something
  38. >I misunderstand?
  39.  
  40. This is why people really should READ the documentation before posting.
  41. This is by no means a bug, just an incorrect way of calling libm.
  42.  
  43. You need to compile as follows:
  44.  
  45. gcc -o test_sqrt test_sqrt.c -lm
  46.  
  47. By having the -lm at the end, gcc will include the routines it finds it needs
  48. from your program. If you put it at the front, it won't know what to include
  49. and will just discard the library.
  50.  
  51. James
  52.