home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!psinntp!ibism!ghica
- From: ghica@fig.citib.com (Renato Ghica)
- Subject: Re: Problem with BC++ 3.0 TLINK and missing symbols
- Message-ID: <C03IKB.IC4@fig.citib.com>
- Originator: ghica@duck
- Sender: news@fig.citib.com
- Organization: Citibank IBISM
- References: <33820012@hpcuhe.cup.hp.com>
- Date: Wed, 30 Dec 1992 23:28:59 GMT
- Lines: 78
-
-
- In article <33820012@hpcuhe.cup.hp.com>, defaria@hpcuhe.cup.hp.com (Andy DeFaria) writes:
- |> I have been receiving errors from Borland C++ 3.0 of the form:
- |>
- |>
- |> Linker Error: Undefined symbol foo<int>::foobar() in module BAR.C
- |>
- |> given the following files:
- |>
- |> FOO.H:
- |> ------
- |> template <class TYPE>
- |> class foo {
- |> private:
- |> int i;
- |> public:
- |> void foobar (void);
- |> };
- |>
- |> FOO.C:
- |> ------
- |> #include "foo.h"
- |>
- |> template <class TYPE>
- |> void foo<TYPE>::foobar (void) {
- |> i++;
- |> } // foobar
- |>
- |> BAR.C:
- |> ------
- |> #include "foo.h"
- |>
- |> void main (void) {
- |> foo<int> x;
- |>
- |> x.foobar ();
- |> } // main
- |>
- |> These example is a chopped down version of the real one that I had originally
- |> had had problems with. Notice that there is no need for a template anymore as
- |> TYPE is not really used. I am using Borland C++ 3.0 and in the IDE I create a
- |> project file that has both FOO.C and BAR.C. Every thing compiles but fails to
- |> link with the above message. Why?
-
-
- with BC 3.1,
-
- The linker does not see the definition of foo<int>::foobar().
- This is because pre-compiling the foo.c file does not implement
- the <int> instantiation. This does not seem to be the case in other
- compilers (ie SUN's).
-
-
- solution:
-
- I'm not saying this is the best, but it works for me. I've tried
- various #pragmas switches before giving up and going the brute force
- method:
-
- [conditionally include foo.c or move the foo.c source into foo.h]
- in foo.h
- ie
-
- FOO.H
- // template function definition
-
- #ifdef SOMEDEF
- #include <foo.c>
- #endif
-
- This way the compiler will "generate" the member function template
- definition at compile time.
- ---------------------------------
- --
-
- "delete *this"
-
- "These views are my own. / Mail me or Flame me"
-