home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15859 < prev    next >
Encoding:
Text File  |  1992-11-07  |  1.6 KB  |  68 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!sun-barr!sh.wide!fgw!fdm!flab!zodiac!zodiac!vander
  2. From: vander@flab.fujitsu.co.jp (Mike van der Velden)
  3. Newsgroups: comp.lang.c++
  4. Subject: undefined symbol... sometimes
  5. Message-ID: <VANDER.92Nov6145301@vancouver.stars.flab.Fujitsu.co.jp>
  6. Date: 6 Nov 92 05:53:01 GMT
  7. Sender: news@zodiac.hi.flab.fujitsu.co.jp
  8. Organization: Fujitsu Laboratories Ltd., Kawasaki, Japan
  9. Lines: 56
  10. Nntp-Posting-Host: vancouver.hi.flab.fujitsu.co.jp
  11.  
  12. I have a curious problem.  If I have the following three files:
  13.  
  14. base.h:
  15. ------
  16.     template <class T>
  17.     class Base {
  18.     public:
  19.         void func ();
  20.         //...
  21.     };
  22.  
  23.  
  24. base.cc:
  25. -------
  26.     #include "base.h"
  27.  
  28.     template<class T> void Base<T>::func ( )
  29.     {
  30.         //...
  31.     }
  32.  
  33.  
  34. main.cc:
  35. -------
  36.     #include "base.h"
  37.  
  38.     main ()
  39.     {
  40.         class Derived : public Base<Derived> {
  41.             //...
  42.         };
  43.  
  44.         Derived   test;
  45.         test.func ();
  46. }
  47.  
  48.  
  49. And compile with the command "g++ base.cc main.cc"   I get the
  50. following linker error:
  51.  
  52.     ld: Undefined symbol
  53.        _func__t4Base1ZQ24main7Derived
  54.     collect: /usr/bin/ld returned 2 exit status
  55.  
  56.  
  57. On the other hand, if I put everything in one file, everything
  58. compiles fine.  I gather that the compiler is mangling the function
  59. name in one file differently than it does in other files.  Have I
  60. missed something?  Is this really correct behavior?  Is there a
  61. work-around?
  62.  
  63. --
  64. Mike van der Velden             
  65. s-mail: Distributed Systems Laboratory, Fujitsu Laboratories Ltd.
  66.         1015, Kamikodanaka Nakahara-ku, Kawasaki 211, Japan
  67. e-mail: vander@flab.fujitsu.co.jp
  68.