* Template compilation
@ 1998-05-07 10:22 Alexander Sclearuc
1998-05-07 17:39 ` JC Loredo-Osti
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alexander Sclearuc @ 1998-05-07 10:22 UTC (permalink / raw)
To: egcs
Hi,
I try to compile a simple template example (see attachments)
and I get the next error:
Undefined first referenced
symbol in file
ostream & operator<<<int>(ostream &, array1<int> const &)template.o
a.out: fatal error: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
My system is SCO 5.0.2 and I use egcs-1.0.2 (build by me too:(
with no flags on command line
The standard C++ compiler for SCO (CC) compiles this example with
no problems.
What is the problem?
PS. I haven't programmed in C++ for more than 2 years, so, may
be I really forgot C++;) But not the basics;)
--
Alexander Sclearuc Phone: (373) 2 21 20 96
NetInfo S.R.L. Fax: (373) 2 21 20 96
Chisinau (373) 2 24 00 83
Moldova, Republic of mailto:avs@netinfo.moldova.net
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template compilation
1998-05-07 10:22 Template compilation Alexander Sclearuc
1998-05-07 17:39 ` JC Loredo-Osti
@ 1998-05-07 17:39 ` Alexandre Oliva
1998-05-08 7:00 ` Alexander Sclearuc
1998-05-07 22:44 ` Robert Lipe
2 siblings, 1 reply; 6+ messages in thread
From: Alexandre Oliva @ 1998-05-07 17:39 UTC (permalink / raw)
To: Alexander Sclearuc; +Cc: egcs
Alexander Sclearuc <avs@netinfo.moldova.net> writes:
> [1 <text/plain; US-ASCII (7bit)>]
> Hi,
> I try to compile a simple template example (see attachments)
> and I get the next error:
> Undefined first referenced
> symbol in file
> ostream & operator<<<int>(ostream &, array1<int> const &)template.o
Every template definition must be available whenever it is used for it
to be implicitly instantiated (unless the template is defined with the
`export' keyword, which is not implemented yet, anyway). So, move the
contents of template1.C into template1.h and it should work.
> The standard C++ compiler for SCO (CC) compiles this example with
> no problems.
It probably uses some non-standard template repository mechanism.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template compilation
1998-05-07 10:22 Template compilation Alexander Sclearuc
@ 1998-05-07 17:39 ` JC Loredo-Osti
1998-05-07 17:39 ` Alexandre Oliva
1998-05-07 22:44 ` Robert Lipe
2 siblings, 0 replies; 6+ messages in thread
From: JC Loredo-Osti @ 1998-05-07 17:39 UTC (permalink / raw)
To: Alexander Sclearuc; +Cc: egcs
On Thu, 7 May 1998, Alexander Sclearuc wrote:
> I try to compile a simple template example (see attachments)
> and I get the next error:
> Undefined first referenced
> symbol in file
> ostream & operator<<<int>(ostream &, array1<int> const &)template.o
> a.out: fatal error: Symbol referencing errors. No output written to a.out
>
If you put your template1.C file in template1.h, you would compile without
problems. (g++ needs to see everything, I guess). Some thing like,
template1.h
------------
ifndef __template1_h
#define __template1_h
#include <iostream.h>
template<class T>
class array1 {
...
};
template<class T>
inline ostream& operator<<(ostream& os, const array1<T>& a) {
for (int i = 0; i < 4; i++)
os << a[i] << " ";
return os;
}
#endif
--------
-j
email: josti@mscs.dal.ca
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template compilation
1998-05-07 10:22 Template compilation Alexander Sclearuc
1998-05-07 17:39 ` JC Loredo-Osti
1998-05-07 17:39 ` Alexandre Oliva
@ 1998-05-07 22:44 ` Robert Lipe
2 siblings, 0 replies; 6+ messages in thread
From: Robert Lipe @ 1998-05-07 22:44 UTC (permalink / raw)
To: Alexander Sclearuc, egcs
> I try to compile a simple template example (see attachments)
> and I get the next error:
Others that know C++ and g++ addressed this question. I'll just
throw in some SCO-specific trivia for free.
> My system is SCO 5.0.2 and I use egcs-1.0.2 (build by me too:(
[ munch ]
> The standard C++ compiler for SCO (CC) compiles this example with
> no problems.
Assuming you're using the CC that ships as part of the SCO OpenServer
Development System and not the CC that ships as part of the (new) U/ODK,
you're talking about a Cfront mutant that is mostly of early 1990's
vintage.
I don't think it's at all safe to consider this compiler anything
resembling authoritative regarding C++ as it exists in the late '90's.
There are surely reasons why everyone, including SCO defected from
Cfront.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Re: Template compilation
1998-05-07 17:39 ` Alexandre Oliva
@ 1998-05-08 7:00 ` Alexander Sclearuc
1998-05-09 0:06 ` Martin von Loewis
0 siblings, 1 reply; 6+ messages in thread
From: Alexander Sclearuc @ 1998-05-08 7:00 UTC (permalink / raw)
To: egcs
Alexandre Oliva wrote:
> > I try to compile a simple template example (see attachments)
> > and I get the next error:
> > Undefined first referenced
> > symbol in file
> > ostream & operator<<<int>(ostream &, array1<int> const &)template.o
>
> Every template definition must be available whenever it is used for it
> to be implicitly instantiated (unless the template is defined with the
> `export' keyword, which is not implemented yet, anyway). So, move the
> contents of template1.C into template1.h and it should work.
Thank you for your answer, this variant works.
But I still have a question.
I compiled recently with MSVC one library and all was OK.
The README file says that the library could be compiled with
EGCS-1.0.2, so I tried to compile the library with it.
And I get a lot of errors like one pointed above.
It took me almost a day to understand what the problem is;)
I don't want to change all library sources and
I would like to know what the C++ standard says
about templates (from this point of view)
> > The standard C++ compiler for SCO (CC) compiles this example with
> > no problems.
> It probably uses some non-standard template repository mechanism.
Yes, it is a Cfront and it creates a repository directory
--
Alexander Sclearuc Phone: (373) 2 21 20 96
NetInfo S.R.L. Fax: (373) 2 21 20 96
Chisinau (373) 2 24 00 83
Moldova, Republic of mailto:avs@netinfo.moldova.net
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Template compilation
1998-05-08 7:00 ` Alexander Sclearuc
@ 1998-05-09 0:06 ` Martin von Loewis
0 siblings, 0 replies; 6+ messages in thread
From: Martin von Loewis @ 1998-05-09 0:06 UTC (permalink / raw)
To: avs; +Cc: egcs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]
> I don't want to change all library sources and I would like to know
> what the C++ standard says about templates (from this point of view)
[temp]/6 says
>> A namespaceÂscope declaration or definition of a nonÂinline
>> function template, a nonÂinline member function template, a
>> nonÂinline member function of a class template or a static data
>> member of a class template may be preceded by the export
>> keyword. If such a template is defined in the same translation unit
>> in which it is declared as exported, the definition is considered
>> to be *exported*.
Since you do not use the export keyword, your templates are not
exported.
With this definition, [temp]/8 says
>> A nonÂexported template that is neither explicitly specialized nor
>> explicitly instantiated must be defined in every translation unit
>> in which it is implicitly instantiated (14.7.1) or explicitly
>> instantiated (14.7.2); no diagnostic is required.
Since you instantiate templates which you didn't export, you must
define them in the translation unit were they are implicitly
instantiated.
So, your library is wrong, and egcs is right. MSVC is also right,
since it does not need to diagnose this violation.
As Alexandre points out, the export keyword is currently not supported
by egcs, so you'll have to define everything you instantiate.
Regards,
Martin
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1998-05-09 0:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-07 10:22 Template compilation Alexander Sclearuc
1998-05-07 17:39 ` JC Loredo-Osti
1998-05-07 17:39 ` Alexandre Oliva
1998-05-08 7:00 ` Alexander Sclearuc
1998-05-09 0:06 ` Martin von Loewis
1998-05-07 22:44 ` Robert Lipe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).