home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / bsd / 11120 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  2.0 KB

  1. Path: sparky!uunet!pipex!bnr.co.uk!uknet!edcastle!aiai!richard
  2. From: richard@aiai.ed.ac.uk (Richard Tobin)
  3. Newsgroups: comp.unix.bsd
  4. Subject: Re: [386bsd] Strange behavior of the system.
  5. Message-ID: <8144@skye.ed.ac.uk>
  6. Date: 11 Jan 93 15:21:28 GMT
  7. References: <3871@tansei1.tansei.cc.u-tokyo.ac.jp>
  8. Sender: news@aiai.ed.ac.uk
  9. Organization: HCRC, University of Edinburgh
  10. Lines: 39
  11.  
  12. In article <3871@tansei1.tansei.cc.u-tokyo.ac.jp> mhiroshi@tansei.cc.u-tokyo.ac.jp (H. Murakami) writes:
  13. >I encountered a unbelieavable behavior of the system now.
  14. >If I linked the object files using gcc2 then the executable
  15. >outputs just two warning.
  16. >However, if I make the object archive first, and then
  17. >link is made using the gcc2 for the object and the library,
  18. >the result is different!
  19.  
  20. >How this can be possible????
  21.  
  22. It would help if you told us more about your program.
  23.  
  24. A possible explanation is this:
  25.  
  26. Object files and libraries are processed sequentially by the linker.
  27. Object files are always linked in.  Modules from libraries are only
  28. linked in if they define a symbol that is (at the time the library
  29. is processed) referenced and undefined.
  30.  
  31. Suppose your program calls a function in the standard library (say
  32. printf).  This library function calls another library function (say
  33. vfprintf).  If you link your program with a .o file defining vfprintf,
  34. that version of vfprintf will be used, and the one in the standard
  35. library ignored.  On the other hand, if you link with a library that
  36. defines vfprintf (but not printf), the linker will not use your
  37. vfprintf because it isn't referenced in your program.  When it comes
  38. to process libc.a, it will link in printf, which will result in an
  39. undefined reference to vfprintf.  It therefore links in the version of
  40. vfprintf from libc.a.
  41.  
  42. Libraries are not just like a big object file.  If that's what you
  43. want then combine your .o files into one using "ld -r" rather than
  44. "ar".
  45.  
  46. -- Richard
  47. -- 
  48. Richard Tobin,
  49. Human Communication Research Centre,                       R.Tobin@ed.ac.uk
  50. Edinburgh University.
  51.