home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18571 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.1 KB  |  91 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!psinntp!ibism!ghica
  3. From: ghica@fig.citib.com (Renato Ghica)
  4. Subject: Re: Problem with BC++ 3.0 TLINK and missing symbols
  5. Message-ID: <C03IKB.IC4@fig.citib.com>
  6. Originator: ghica@duck
  7. Sender: news@fig.citib.com
  8. Organization: Citibank IBISM
  9. References:  <33820012@hpcuhe.cup.hp.com>
  10. Date: Wed, 30 Dec 1992 23:28:59 GMT
  11. Lines: 78
  12.  
  13.  
  14. In article <33820012@hpcuhe.cup.hp.com>, defaria@hpcuhe.cup.hp.com (Andy DeFaria) writes:
  15. |> I have been receiving errors from Borland C++ 3.0 of the form:
  16. |> 
  17. |> 
  18. |> Linker Error: Undefined symbol foo<int>::foobar() in module BAR.C
  19. |> 
  20. |> given the following files:
  21. |> 
  22. |> FOO.H:
  23. |> ------
  24. |> template <class TYPE>
  25. |> class foo {
  26. |>    private:
  27. |>       int i;
  28. |>    public:
  29. |>       void foobar (void);
  30. |> };
  31. |> 
  32. |> FOO.C:
  33. |> ------
  34. |> #include "foo.h"
  35. |> 
  36. |> template <class TYPE>
  37. |> void foo<TYPE>::foobar (void) {
  38. |>   i++;
  39. |> } // foobar
  40. |> 
  41. |> BAR.C:
  42. |> ------
  43. |> #include "foo.h"
  44. |> 
  45. |> void main (void) {
  46. |>    foo<int> x;
  47. |> 
  48. |>    x.foobar ();
  49. |> } // main
  50. |> 
  51. |> These example is a chopped down version of the real one that I had originally
  52. |> had had problems with.  Notice that there is no need for a template anymore as
  53. |> TYPE is not really used.  I am using Borland C++ 3.0 and in the IDE I create a
  54. |> project file that has both FOO.C and BAR.C.  Every thing compiles but fails to
  55. |> link with the above message.  Why?
  56.  
  57.  
  58. with BC 3.1,
  59.  
  60. The linker does not see the definition of foo<int>::foobar().
  61. This is because pre-compiling the foo.c file does not implement
  62. the <int> instantiation. This does not seem to be the case in other
  63. compilers (ie SUN's).
  64.  
  65.  
  66. solution:
  67.  
  68. I'm not saying this is the best, but it works for me. I've tried
  69. various #pragmas switches before giving up and going the brute force
  70. method:
  71.  
  72. [conditionally include foo.c or move the foo.c source into foo.h]
  73. in foo.h
  74. ie
  75.  
  76. FOO.H
  77. // template function definition
  78.  
  79. #ifdef SOMEDEF
  80. #include <foo.c>
  81. #endif
  82.  
  83. This way the compiler will "generate" the member function template
  84. definition at compile time.
  85. ---------------------------------
  86. -- 
  87.  
  88. "delete *this"
  89.  
  90. "These views are my own. / Mail me or Flame me"
  91.