473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

g++ troubles with templates

Hello,
I have trouble with g++ code related to templates in program of
mine,

perhaps anybody can help me with that.
I might am doing something wrong with the template names....
Compiling my code, I get the compiler error:
(Yes, I broke the compiler outputs in order to make it more readable)

What is wrong?
Willy

-----------------------------
g++ -g -I. -D___x86___ -D_DEBUG -Wall MainAsx.o PCMFile.o asxio.o
\ FhxError.o Unix4Win.o perrorf.o \
ftt_recursive.o ftt_heterogen.o ftt_base.o \
pointfield.o pointfield_deconvolute.o pointfield_convolute.o -
o asx -lm

MainAsx.o: In function `CalcHFtt2Asx(unsigned int, unsigned int,
double, char*, char*, bool)':
/home/duffy/hafi/Documents/prj/SCIENTIA/PHYSIK/ASX/asx/sw/MainAsx.cpp:
48:
undefined reference to
`FttRecursive<std::complex<double>>::FttRecursive( unsigned int,
unsigned int, double, double)'
collect2: ld returned 1 exit status
make: *** [asx] Fehler 1

------------------------------
------------------------------ I initiate the FttRecursive herein:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <math.h>
#include <complex>

#include "Unix4Win.h"
#include "ftt.h" //this includes both ftt_base.h and ftt_recursive.h
long FrameCount=0;
int CalcHFtt2Asx(unsigned int N,
unsigned int R,
double a ,
char *input,
char *output,
bool recursive)
{
/* .... */
t_ptr_FttBase ftt;
if(recursive) ftt=new FTT(N,R,a,Tx);
else /*...*/
/*...*/
}
===========================

----------------------------- in file ftt_recursive.h I declare:

#ifndef __FTT_RECURSIVE_H
#define __FTT_RECURSIVE_H

#include <complex>
#include <math.h>

#include "ftt_base.h"
template<class t_Data >
class FttRecursive
: public FttBase<t_Data >
{
public:
FttRecursive(unsigned int N=32, unsigned int R=32,
double a=0.010, double Tx=1.0/11025 );
virtual ~FttRecursive() {};

virtual t_Data *const calc(double *pcm);

protected:
const double E;
};

typedef FttRecursive<std::complex<double FTT;

#endif
===========================
------------------------------ in file ftt_recursive.cpp i define:
#include <math.h>
#include <complex>
#include "ftt_recursive.h"

template<class t_Data >
FttRecursive<t_Data >::FttRecursive(unsigned int N_, unsigned int R_,
double a_, double Tx_)
: FttBase<t_Data>( N_, R_, a_, Tx_)
, E(exp(-a_*Tx_))
{

}

===========================
----------------------------- in file ftt_base.h I declare:
#ifndef __FTT_BASE_H
#define __FTT_BASE_H

#include <complex>
#include <math.h>

#include "pointfield.h"

template<class t_Data>
class FttBase
{
public:
FttBase(unsigned int N=32, unsigned int R=32, double
a=0.010, double Tx=1.0/11025);
virtual ~FttBase();

virtual t_Data *const calc(double *pcm)=0;

t_Data* const convolute(t_Data* con_in_spectrum);

protected:
const std::complex<doubleI;

unsigned int L;

unsigned int N,R;

double a;
double Tx;

unsigned int M;
t_Data *P_M;

PointField<t_Datatarget;
PointField<t_Datasource;
PointField<t_Datapsf;

bool create_psf(PointField<t_Data&PSF);

t_Data psf_value_function(double delta_w, double delta_t);
};
typedef FttBase<std::complex<double *t_ptr_FttBase;

#endif

==============================

Feb 20 '07 #1
4 1558
WillyFoobar wrote:
Hello,
I have trouble with g++ code related to templates in program of
mine,

perhaps anybody can help me with that.
I might am doing something wrong with the template names....
Compiling my code, I get the compiler error:
(Yes, I broke the compiler outputs in order to make it more readable)

What is wrong?
Willy

-----------------------------
g++ -g -I. -D___x86___ -D_DEBUG -Wall MainAsx.o PCMFile.o asxio.o
\ FhxError.o Unix4Win.o perrorf.o \
ftt_recursive.o ftt_heterogen.o ftt_base.o \
pointfield.o pointfield_deconvolute.o pointfield_convolute.o -
o asx -lm

MainAsx.o: In function `CalcHFtt2Asx(unsigned int, unsigned int,
double, char*, char*, bool)':
/home/duffy/hafi/Documents/prj/SCIENTIA/PHYSIK/ASX/asx/sw/MainAsx.cpp:
48:
undefined reference to
`FttRecursive<std::complex<double>>::FttRecursive( unsigned int,
unsigned int, double, double)'
collect2: ld returned 1 exit status
make: *** [asx] Fehler 1

------------------------------
------------------------------ I initiate the FttRecursive herein:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <math.h>
#include <complex>

#include "Unix4Win.h"
#include "ftt.h" //this includes both ftt_base.h and ftt_recursive.h
long FrameCount=0;
int CalcHFtt2Asx(unsigned int N,
unsigned int R,
double a ,
char *input,
char *output,
bool recursive)
{
/* .... */
t_ptr_FttBase ftt;
if(recursive) ftt=new FTT(N,R,a,Tx);
else /*...*/
/*...*/
}
===========================

----------------------------- in file ftt_recursive.h I declare:

#ifndef __FTT_RECURSIVE_H
#define __FTT_RECURSIVE_H

#include <complex>
#include <math.h>

#include "ftt_base.h"
template<class t_Data >
class FttRecursive
: public FttBase<t_Data >
{
public:
FttRecursive(unsigned int N=32, unsigned int R=32,
double a=0.010, double Tx=1.0/11025 );
virtual ~FttRecursive() {};

virtual t_Data *const calc(double *pcm);

protected:
const double E;
};

typedef FttRecursive<std::complex<double FTT;

#endif
===========================
------------------------------ in file ftt_recursive.cpp i define:
#include <math.h>
#include <complex>
#include "ftt_recursive.h"

template<class t_Data >
FttRecursive<t_Data >::FttRecursive(unsigned int N_, unsigned int R_,
double a_, double Tx_)
: FttBase<t_Data>( N_, R_, a_, Tx_)
, E(exp(-a_*Tx_))
{

}

===========================
----------------------------- in file ftt_base.h I declare:
#ifndef __FTT_BASE_H
#define __FTT_BASE_H

#include <complex>
#include <math.h>

#include "pointfield.h"

template<class t_Data>
class FttBase
{
public:
FttBase(unsigned int N=32, unsigned int R=32, double
a=0.010, double Tx=1.0/11025);
virtual ~FttBase();

virtual t_Data *const calc(double *pcm)=0;

t_Data* const convolute(t_Data* con_in_spectrum);

protected:
const std::complex<doubleI;

unsigned int L;

unsigned int N,R;

double a;
double Tx;

unsigned int M;
t_Data *P_M;

PointField<t_Datatarget;
PointField<t_Datasource;
PointField<t_Datapsf;

bool create_psf(PointField<t_Data&PSF);

t_Data psf_value_function(double delta_w, double delta_t);
};
typedef FttBase<std::complex<double *t_ptr_FttBase;

#endif

==============================
You will need to copy the entire contents of
ftt_recursive.cpp to ftt_recursive.h since
the template export keyword has not been implemented
by the GNU folks.

Or you can #include "ftt_recursive.cpp" into
ftt_recursive.h. I normally do not like this but the
GNU folks do it quite often in the standard headers. :)

Feb 20 '07 #2
WillyFoobar wrote:
[template linker error redacted]
Piyo gave you the answer, but to give a bit more reference,

It's a FAQ. http://www.parashift.com/c++-faq-lit...html#faq-35.12

Actually, it's a series of FAQS. 35.12 through about 35.15.
Feb 20 '07 #3
Thank you to "Piyo" and "red floyd"

The tip and the faq were helpfull.

Here is what I needed to do to get it working.

I added #cpp commndo lines like at all *.cpp source and *.h header
files
---------------------------------------
#ifndef __FTT_BASE_CPP
#define __FTT_BASE_CPP

/*..*/
#endif
====================
I also added in each header file a inclusion to the related cpp-files
and a dummy template declaration

---------------------------------------
#ifndef __FTT_BASE_H
#define __FTT_BASE_H
/*...*/

#include "ftt_base.cpp"
template class FttBase<std::complex<double;
#endif
====================

Feb 21 '07 #4
WillyFoobar wrote:
Thank you to "Piyo" and "red floyd"

The tip and the faq were helpfull.

Here is what I needed to do to get it working.

I added #cpp commndo lines like at all *.cpp source and *.h header
files
---------------------------------------
#ifndef __FTT_BASE_CPP
#define __FTT_BASE_CPP
Those are VERY bad include guards. Any identifier with two consecutive
underscores is reserved to the implementation. That means you may not
define it for your own use. Lest you think about just removing one, any
identifier with a leading underscore followed by an upper case letter is
similarly reserved to the implementation.

I would use

#ifndef FTT_BASE_CPP_
Feb 21 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: lmckaha | last post by:
Hi, Mysql version: 3.23.49 Solaris version: 2.7 gcc compiler version: 2.95.2 Python : 2.2.2 I'm evaluating the C and C++ API to decide which one to bye but I have many troubles.
3
by: justin.adam.miller | last post by:
I've been trying to use the sfinae principle in some code and have been getting many compiler errors. So I decided to try a very simplified version to see if I had the idea correct. Here's the...
15
by: Improving | last post by:
I have a template class that has static members, so in the .cpp file I have defined them with templated definitions. Now when in a different ..cpp file that includes the header file for the...
0
by: Michal | last post by:
I have troubles with instaling .Net Framework 2.0 (Beta 2 - 2.0.50215). The main instalation went just fine, troubles begin with my attemt to run aspnet_regiss.exe -i. Asp.Net is instaled into IIS...
22
by: Ted | last post by:
This page http://homepage.ntlworld.com/r.a.mccartney/test/utf-8_test_file_hacked_for_ie_with_local_dtd.xml doesn't work properly in Firefox or IE6. The faults are different. In Firefox the...
2
by: Nikolay Moskvichev | last post by:
Hi, When porting application to linux we get compilation errors (undefined variable p in function GetValue()) from gcc 3.4.1 but it compiles well on windows with msvc 7.1 what is problem here ?...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
0
by: JohnIdol | last post by:
VC++6 to VC++2003 - linking troubles -------------------------------------------------------------------------------- Hi All, I successfully ported an application from VC++6 to VS2003. Solved...
1
by: Pegasus | last post by:
Good morning, I'm Filippo Battaglia. We're porting Apache STDCXX under Nanodesktop. We are trying to make nd compatible also with C++ and not only with C. Unfortunately, we're finding different...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.