-
Linkage problem (maybe)
Hi everyone. I am making a program using templates. I'm not very good with templates. Also, I'm using a makefile. I'm not good with makefiles either. The thing is, when I compile, I receive the following error message:
Code:
main.o(.gnu.linkonce.t._Z9algoritmoI6matriz5vetor9simetricaERT0_RKT1_RKS3_RKT_S9_S9_+0x484): In function `vetor& algoritmo<matriz, vetor, simetrica>(simetrica const&, vetor const&, matriz const&, vetor const&, vetor const&)':
/home/abel/Matriz_com_Templates/metodos.h:144: undefined reference to `vetor& Inverso<vetor>(vetor const&)'
main.o(.gnu.linkonce.t._Z9algoritmoI6matriz5vetor9simetricaERT0_RKT1_RKS3_RKT_S9_S9_+0x6f5):/home/abel/Matriz_com_Templates/metodos.h:156: undefined reference to `vetor& Inverso<vetor>(vetor const&)'
...
it repeats for some other lines. This problem arises when I make a call to a function included in . Those undefined references, are included in . I have included ferramentas.h in the metodos.h. I don't have .cpp for these files. My makefile is the following ( a part of it):
Code:
matriz : matriz.o vetor.o vetor_esp.o esparsa.o simetrica.o metodos.o main.o
g++ -g -o matriz matriz.o vetor.o vetor_esp.o esparsa.o simetrica.o main.o
main.o : testematriz.cpp ferramentas.h metodos.h
g++ -g -c testematriz.cpp -o main.o
metodos.o : metodos.h
g++ -g -c metodos.h
matriz.o : matriz.cpp matriz.h
g++ -g -c matriz.cpp
...
When I call for another function in the same "metodos.h" library, it works.
I don't have a clue of what is going wrong, if anyone can help me, I would be very thankful.
Thank you,
Nepper271.
-
What does your implementation of "Inverso" look like?
--
Mats
-
Inverso takes an element of the type 'vetor' (a vector) and returns another element of 'vetor' with the inverse of each element, i.e.
Code:
if v = (v1, v2, ..., vn), inverso(v) = (1/v1, 1/v2, ..., 1/vn).
But this problem is happening with all function called by 'metodos.h' that are in 'ferramentas.h', not only 'inverso'
-
No, I'm not asking what it DOES, I'm asking what the prototype of the function looks like. Peering into my plastic ball [plastic balls are not as good at seeing the future as crystal balls, but they are a lot less expencive], I predict you are missing a const or some such.
--
Mats
-
Oh, sorry, here it is:
Code:
template <typename tipo_matriz, typename tipo_vetor>
tipo_vetor & Inverso(tipo_vetor const & x) {
int n = x.size();
tipo_vetor *y = new tipo_vetor(n);
for (int i = 1; i <= n; i++) (*y)(i) = 1.0/x(i);
return *y;
}
-
Thank you everyone, but the problem is solved, and had nothing to do with anything I said before
I had just put some extra typenames in some functions, (like the above, see?)
Thank you all,
Nepper271
-
See, that plastic ball is almost useful :)
--
Mats