home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!agate!doc.ic.ac.uk!uknet!edcastle!dcs.ed.ac.uk!sct
- From: sct@dcs.ed.ac.uk (Stephen Tweedie)
- Newsgroups: comp.os.linux
- Subject: Re: gcc 2.3.3 problem
- Message-ID: <SCT.93Jan26194220@ascrib.dcs.ed.ac.uk>
- Date: 26 Jan 93 19:42:20 GMT
- References: <1993Jan25.144702.4734@hp9000.csc.cuhk.hk>
- Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
- Organization: University of Edinburgh Dept. of Computer Science, Scotland
- Lines: 39
- In-Reply-To: a080700@hp9000.csc.cuhk.hk's message of 25 Jan 93 14:47:02 GMT
-
- 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
-
- > 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 a feature of most (if not all) unix C compilers.
-
- The compiler command (cc or gcc) does not compile your program, but
- rather just invokes the preprocessor, compiler and linker as
- necessary. It passess the appropriate command line arguments and
- options to each sub-program.
-
- However, it uses the position of an option on the command line to
- determine which options to pass to which program. Linking is done
- after compilation, so linker options should come after compiler
- options and arguments on the gcc command line.
-
- 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".
-
- Cheers,
- Stephen Tweedie.
- ---
- Stephen Tweedie <sct@uk.ac.ed.dcs> (Internet: <sct@dcs.ed.ac.uk>)
- Department of Computer Science, Edinburgh University, Scotland.
-