Very basic question. 
July 22nd, 2005, 04:15 PM
| | | |
My native language is c, but I have the unpleasant task of porting a C++
code from SGI MIPS to Linux Opteron, I have no help from the author of the
code.
One of several problems is that my g++ (3.3.3) compiler balks at expressions
like <int>: for example if Scan is a well defined object, the compiler balks
at Scan<int> ::~Scan; the error message is 'undefined reference to
Scan<int>'. Is <int> a cast operator? What can be done to avoid the error
message?
Thanks in advance.
--
ESOJAY | 
July 22nd, 2005, 04:15 PM
| | | | re: Very basic question.
"ESOJAY" <esojay54@hotmail.com> wrote in message
news:cbbr8l$b3v$1@news.ox.ac.uk...[color=blue]
> My native language is c, but I have the unpleasant task of porting a C++
> code from SGI MIPS to Linux Opteron, I have no help from the author of the
> code.
>
> One of several problems is that my g++ (3.3.3) compiler balks at[/color]
expressions[color=blue]
> like <int>: for example if Scan is a well defined object, the compiler[/color]
balks[color=blue]
> at Scan<int> ::~Scan; the error message is 'undefined reference to
> Scan<int>'. Is <int> a cast operator? What can be done to avoid the error
> message?
>
> Thanks in advance.
>[/color]
Looks like a template parameter, but who can say unless you post at the very
least complete line of code.
POST MORE CODE.
john | 
July 22nd, 2005, 04:15 PM
| | | | re: Very basic question.
"John Harrison" <john_andronicus@hotmail.com> wrote in message
news:2jt9mhF11ujr5U1@uni-berlin.de...[color=blue]
>
> "ESOJAY" <esojay54@hotmail.com> wrote in message
> news:cbbr8l$b3v$1@news.ox.ac.uk...[color=green]
> > My native language is c, but I have the unpleasant task of porting a C++
> > code from SGI MIPS to Linux Opteron, I have no help from the author of[/color][/color]
the[color=blue][color=green]
> > code.
> >
> > One of several problems is that my g++ (3.3.3) compiler balks at[/color]
> expressions[color=green]
> > like <int>: for example if Scan is a well defined object, the compiler[/color]
> balks[color=green]
> > at Scan<int> ::~Scan; the error message is 'undefined reference to
> > Scan<int>'. Is <int> a cast operator? What can be done to avoid the[/color][/color]
error[color=blue][color=green]
> > message?
> >
> > Thanks in advance.
> >[/color]
>
> Looks like a template parameter, but who can say unless you post at the[/color]
very[color=blue]
> least complete line of code.
>
> POST MORE CODE.
>
> john[/color]
The code looks like:
#include <file1>
#include <file2>
#include <file3>
using namespace std;
#include "file4"
#include "file5"
typedef vector<double> Var1;
typedef double Var2;
template <class T>
class func {
public:
func (vector<int *> Var3, int *Var4, int *Var5 = NULL) ;
func (vector<Var1> Var6) ;
func (vector<Var2>& Var6) ;
func (func<T> &m) ;
~func(void);
...........................
void func2(bool b) ;
protected:
.....................
};
The offending line is:
func<int>::func2(bool).
Linker error is undefined reference to func<int>::func2(bool).
Thanks,
--
ESOJAY | 
July 22nd, 2005, 04:15 PM
| | | | re: Very basic question.
"ESOJAY" <esojay54@hotmail.com> wrote in message
news:cbc035$crs$1@news.ox.ac.uk...[color=blue]
>
> "John Harrison" <john_andronicus@hotmail.com> wrote in message
> news:2jt9mhF11ujr5U1@uni-berlin.de...[color=green]
> >
> > "ESOJAY" <esojay54@hotmail.com> wrote in message
> > news:cbbr8l$b3v$1@news.ox.ac.uk...[color=darkred]
> > > My native language is c, but I have the unpleasant task of porting a[/color][/color][/color]
C++[color=blue][color=green][color=darkred]
> > > code from SGI MIPS to Linux Opteron, I have no help from the author of[/color][/color]
> the[color=green][color=darkred]
> > > code.
> > >
> > > One of several problems is that my g++ (3.3.3) compiler balks at[/color]
> > expressions[color=darkred]
> > > like <int>: for example if Scan is a well defined object, the compiler[/color]
> > balks[color=darkred]
> > > at Scan<int> ::~Scan; the error message is 'undefined reference to
> > > Scan<int>'. Is <int> a cast operator? What can be done to avoid the[/color][/color]
> error[color=green][color=darkred]
> > > message?
> > >
> > > Thanks in advance.
> > >[/color]
> >
> > Looks like a template parameter, but who can say unless you post at the[/color]
> very[color=green]
> > least complete line of code.
> >
> > POST MORE CODE.
> >
> > john[/color]
>
> The code looks like:
>
> #include <file1>
> #include <file2>
> #include <file3>
> using namespace std;
>
> #include "file4"
> #include "file5"
>
> typedef vector<double> Var1;
> typedef double Var2;
>
> template <class T>
> class func {
>
> public:
> func (vector<int *> Var3, int *Var4, int *Var5 = NULL) ;
> func (vector<Var1> Var6) ;
> func (vector<Var2>& Var6) ;
> func (func<T> &m) ;
> ~func(void);
> ...........................
> void func2(bool b) ;
>
> protected:
> .....................
> };
>
> The offending line is:
> func<int>::func2(bool).
> Linker error is undefined reference to func<int>::func2(bool).
>
> Thanks,
>[/color]
A linker error means that you've failed to define the entity named. In this
case you've failed to give a definition for the method func2, in the class
template func<T>, in the case when T equals int.
Now there is no such definition in the code you've posted but maybe the
definition is somewhere else in your code. Do you see a function looking
something like this
template <class T>
void func<T>::func2(bool ...)
{
...
}
somewhere in your code? Its because that hasn't been included in your code
or has been included but not in the right place that you are getting linker
errors.
It would also be worth looking around and seeing where the method func2 is
actually being called.
john | 
July 22nd, 2005, 04:16 PM
| | | | re: Very basic question.
ESOJAY wrote:[color=blue]
> My native language is c, but I have the unpleasant task of porting a C++
> code from SGI MIPS to Linux Opteron, I have no help from the author of the
> code.
>
> One of several problems is that my g++ (3.3.3) compiler balks at expressions
> like <int>: for example if Scan is a well defined object, the compiler balks
> at Scan<int> ::~Scan; the error message is 'undefined reference to
> Scan<int>'. Is <int> a cast operator? What can be done to avoid the error
> message?[/color]
Do you know on what compiler(s) the original code was compiled? Template
instantiation can be handled in several different ways. See the GCC
TexInfo manual, under 'C++ Extensions --> Template Instantiation', or
the comp.lang.c++ FAQ (search the web for that).
--
Regards,
Buster. | 
July 22nd, 2005, 04:17 PM
| | | | re: Very basic question.
On Wed, 23 Jun 2004 14:16:49 +0100 in comp.lang.c++, "ESOJAY"
<esojay54@hotmail.com> wrote,[color=blue]
>The offending line is:
>func<int>::func2(bool).
>Linker error is undefined reference to func<int>::func2(bool).[/color]
Please refer to these topics in Marshall Cline's C++ FAQ and see if they
shed any light on the problem:
[34.12] Why can't I separate the definition of my templates class from
it's declaration and put it inside a .cpp file?
[34.13] How can I avoid linker errors with my template functions?
You can get the FAQ at: http://www.parashift.com/c++-faq-lite/ |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|