This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: templating in multiple files


On Thu, Nov 04, 2004 at 04:40:02PM +0100, Eagle wrote:

> Hi all,
> As my understanding this should be the correct mailing list for this issue.

It would have been better suited to gcc-help, as this list is about the
development of the libstdc++ library, not help using it or help using
GCC. You also haven't asid which version of GCC you are using, but it
doesn't really matter for this question.

> I'm porting from VC6 to gcc a set of numerical software, and I did came 
> across an issue
> which I reproduced in the following simple test case:
[snip]
> [diego@persefone t2]$ g++ template.cpp Main.cpp
> /tmp/ccEZpSk7.o: In function `main':
> /tmp/ccEZpSk7.o(.text+0x38): undefined reference to `void 
> joe::parse<int>(int, int)'
> /tmp/ccEZpSk7.o(.text+0x53): undefined reference to `void 
> joe::parse<double>(int, double)'
> collect2: ld returned 1 exit status
> [diego@persefone t2]$
> 
> The fact is that if all the code is sticked into one file it works fine.
> 
> Questions are:
> To me it looks perfectly standard ANSI, as it works in one file It should 
> work in multiple files, correct ?

No. The definition of a template must be visible when it is
instantiated (unless you use "export", but neither VC++ nor GCC support
that keyword).

The usual solution is to include the template definition in template.h
and get rid of the template.cpp file. This effectively means the code is
all in one file again, but is standard-conforming C++.

jon


-- 
"No one pretends that democracy is perfect or all wise.
 It has been said that democracy is the worst form of government,
 except for all the others that have been tried from time to time."
	- Winston Churchill, 1947.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]