Topic: Problem when compiling with Sun C++
Author: miniussi@labri.u-bordeaux.fr (Alain MINIUSSI)
Date: 27 Oct 1994 14:53:31 GMT Raw View
In article <1994Oct25.101619.23806@news.unige.ch>, baujard@cui.unige.ch (BAUJARD Olivier) writes:
|> Hi,
|>
|> I'm using Sun C++ 4.0 on Solaris on a Sparc. I have written an application
|> using templates. The structure of the application is the following:
|> *.h files containing classes (templated) definition/methods propotypes
|> *.C files containing methods (templated) body
|>
|> When compiling, I got the following messages:
|>
|> "test_all.C", line 66: Information: Instantiating ***.
|> "test_all.C", line 66: Error: Could not find source ***.
|>
|> where *** is one of the instantiated method.
|>
|> What does it mean ? All *.h are correctly included and the compiler should know
|> about the methods.
|>
|> Is there anybody here using templates with Sun C++ ?
|>
|> I saw a lot of questions about similar troubles with compiler
|> such as gcc but no really convincing answers. So, any pointers
|> are welcomed,
I have a similar problem, and it seems to be a bug, here is the code:
dragon > miniussi : more *
::::::::::::::
bug.cc
::::::::::::::
struct symbol;
int operator==(const symbol&, const symbol&);
struct instruction;
int operator==(const instruction&,const instruction&);
#include "list.h"
#include "cursor.h"
void f(instruction& i, list<instruction>& l) {l.has(i);}
cursor<symbol> branches_to_treat;
::::::::::::::
cursor.cc
::::::::::::::
#include "cursor.h"
#include "list.h"
template <class T> cursor<T>::cursor() {}
template <class T> T& cursor<T>::operator()(void) const
{ return *(T*)0; }
template <class T>
int operator==(const cursor<T>& c1, const cursor<T>& c2)
{ return 1; }
::::::::::::::
cursor.h
::::::::::::::
#ifndef CURSOR_HEADER
#define CURSOR_HEADER
template <class T> struct cursor {
cursor();
T& operator()(void) const;
};
#endif // CURSOR_HEADER
::::::::::::::
list.cc
::::::::::::::
#include "cursor.h"
#include "list.h"
template<class T> void list<T>::has (test t,void *data)
{
cursor<T> c;
t(c(),data);
}
template <class T> void equal(T& t1, void *v)
{ t1==*(T*)v;}
template <class T> void list<T>::has (T& item)
{ has(::equal,&item); }
::::::::::::::
list.h
::::::::::::::
#ifndef LIST_HEADER
#define LIST_HEADER
template <class T> struct list {
typedef void (*test) (T&,void*);
void has (test t,void *d = 0);
void has (T&);
};
#endif // LIST_HEADER
dragon > miniussi : CC -ptv -c bug.cc
template manager : Warning: No valid template database available. Creating default repository "Templates.DB".
template manager : Information: Processing template options file "Templates.DB/Template.opt".
"bug.cc", line 9: Information: Instantiating list<instruction>::has(instruction&).
"bug.cc", line 11: Information: Instantiating cursor<symbol>::cursor().
"list.cc", line 15: Information: Instantiating list<instruction>::has(void(*)(instruction&, void*), void*).
"list.cc", line 15: Information: Instantiating equal(instruction&, void*).
"list.cc", line 8: Information: Instantiating cursor<instruction>::cursor().
"list.cc", line 8: Information: Instantiating cursor<instruction>::operator()().
"list.cc", line 12: Information: Instantiating operator==(const instruction&, const instruction&).
"list.cc", line 12: Error: Could not find source for operator==(const instruction&, const instruction&).
1 Error(s) detected.
this example show that the problem can arise even with non-template code
(the compiler should not atempt to instantiate
"int operator==(const instruction&, const instruction&)" wich is declared as been
extern).
I don't know exactly where is the problem but the funny points are:
1) if you remove, in bug.cc the declaration
cursor<symbol> etc....
the problem concerning "int operator==(const instruction&, const instruction&)"
disappear. (where are no relation betwen instruction and symbol, only their
names are used! and the instantiation begin in a list method), it look like you
need 2 different instantiation to have the problem.
2) if you remove the constructor cursor<T> (and then use a default constructor
in list<T>::has(test t,void*data) the problem disappear (I still don't see
any "logical" connection betwen the two fact)
3) maybe the most significative point: if you remove, in cursor.cc, the
operator==(const cursor<T>& c1, const cursor<T>& c2)
{....}
the problem disppear, maybe there is a problem in the way that the compiler
looks for function. But note that the last operator is never used in the example.
maybe you could try to move some functions in different file in order
to avoid this kind of coincidences.
|> Cheers,
|> Olivier
Alain
--
------------------------------------------------------------------------------
Alain Miniussi |
(avec le "i" avant le "u") | "Mais y connait pas Raoul
e-mail: miniussi@labri.u-bordeaux.fr | ce mec ! il va avoir un
tel : 56 84 69 16 | reveil penible !"
LaBRI, Univ. BORDEAUX I |
351, cours de la Liberation | R. Volfoni
FRANCE |
------------------------------------------------------------------------------
Author: miniussi@labri.u-bordeaux.fr (Alain MINIUSSI)
Date: 27 Oct 1994 10:44:58 GMT Raw View
In article <1994Oct25.101619.23806@news.unige.ch>, baujard@cui.unige.ch (BAUJARD Olivier) writes:
|> Hi,
|>
|> I'm using Sun C++ 4.0 on Solaris on a Sparc. I have written an application
|> using templates. The structure of the application is the following:
|> *.h files containing classes (templated) definition/methods propotypes
|> *.C files containing methods (templated) body
|>
|> When compiling, I got the following messages:
|>
|> "test_all.C", line 66: Information: Instantiating ***.
|> "test_all.C", line 66: Error: Could not find source ***.
|>
|> where *** is one of the instantiated method.
I have the same problem, but in my source,*** is a non-template
operator that should not be instantiated, and the compiler find
the declaration !
|> What does it mean ?
it looks like a bug, and a funny one
|> All *.h are correctly included and the compiler should know
|> about the methods.
|>
|> Is there anybody here using templates with Sun C++ ?
yes
|> I saw a lot of questions about similar troubles with compiler
|> such as gcc but no really convincing answers.
not the same thing, you can use template with SUN C++, you can't
with g++ (at least with the 2.5.8, buggy and stupid instantiation
system).
|> So, any pointers are welcomed,
well I can post my example and show the point where the bug arise, I
think that there is a turnaround, the problem is that the example
is a bit long (500 line) and that I sould remove some code in order
to keep only the interesting part, so I'll do it only if someone
is interested
|>
|> Cheers,
|>
|> Olivier
|>
--
------------------------------------------------------------------------------
Alain Miniussi |
(avec le "i" avant le "u") | Le singe a trop de mains ou pas
e-mail: miniussi@labri.u-bordeaux.fr | assez de pieds pour s'abaisser
tel : 56 84 69 16 | a jouer au football.
LaBRI, Univ. BORDEAUX I |
351, cours de la Liberation | P. Desproges
FRANCE |
------------------------------------------------------------------------------
Author: baujard@cui.unige.ch (BAUJARD Olivier)
Date: Tue, 25 Oct 1994 10:16:19 GMT Raw View
Hi,
I'm using Sun C++ 4.0 on Solaris on a Sparc. I have written an application
using templates. The structure of the application is the following:
*.h files containing classes (templated) definition/methods propotypes
*.C files containing methods (templated) body
When compiling, I got the following messages:
"test_all.C", line 66: Information: Instantiating ***.
"test_all.C", line 66: Error: Could not find source ***.
where *** is one of the instantiated method.
What does it mean ? All *.h are correctly included and the compiler should know
about the methods.
Is there anybody here using templates with Sun C++ ?
I saw a lot of questions about similar troubles with compiler
such as gcc but no really convincing answers. So, any pointers
are welcomed,
Cheers,
Olivier