home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!matt.ksu.ksu.edu!news
- From: probreak@matt.ksu.ksu.edu (James Michael Chacon)
- Newsgroups: comp.os.linux
- Subject: Re: gcc 2.3.3 problem
- Date: 26 Jan 1993 06:36:43 -0600
- Organization: Kansas State University
- Lines: 40
- Message-ID: <1k3b8rINN7o9@matt.ksu.ksu.edu>
- References: <1993Jan25.144702.4734@hp9000.csc.cuhk.hk>
- NNTP-Posting-Host: matt.ksu.ksu.edu
-
- a080700@hp9000.csc.cuhk.hk (Stephen Wong S M) writes:
-
- >I'm using linux 0.99pl4/SLS 1.0/gcc 2.3.3/lib 4.2 and I test the
- >gcc compiler with the following program:-
-
- >test_sqrt.c
- >#include <math.h>
- >#include <stdio.h>
- >main()
- >{ double a;
- > a = 2;
- > printf("square root of 2 is %f\n", sqrt(a));
- >}
-
- >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
-
- >Then I tried another command line:-
- >gcc -o test_sqrt test_sqrt.c /usr/lib/libm.a
-
- >and succeed.
-
- >My question is, is it a bug in gcc 2.3.3/lib 4.2 (libm.a), or something
- >I misunderstand?
-
- This is why people really should READ the documentation before posting.
- This is by no means a bug, just an incorrect way of calling libm.
-
- You need to compile as follows:
-
- gcc -o test_sqrt test_sqrt.c -lm
-
- By having the -lm at the end, gcc will include the routines it finds it needs
- from your program. If you put it at the front, it won't know what to include
- and will just discard the library.
-
- James
-