[SOLVED] Link error - Undefined reference
-
Hello, I am a new QTcreator user and I can't compile a simple program,
I have my class defined and implemented in polynomial.h and polynomial.cpp
I have also main.cpp which (is supposed to) instantiate my class TPolynomial.When I build I get the error:
undefined reference to TPolynomial<int>::TPolynomial()I have found similar topic so I tried to clean, run qmake and rebuild, Qt creates main.o and polynomial.o, they both are in the "build folder" with the make file but it doesn't work, it seems not to find the polynomial.o?
And when I write the implementation of my class in the header it works, so the problem is that Qt doesn't look for in the good folder.
Do I have to specify a folder somewhere in the options?
I don't think because all the files are in the same folder?Thanks.
-
Hi and welcome to devnet,
No, it's not a problem of Qt, you are implementing a template class. See the C++ Super FAQ about the template
-
Thank you for the link.
Under the implementation of the template method, I tried to add the line:
"template void freePolynomial<int>();"I get the error message:
"variable or field 'freePolynomial' declared void"Then I tried to add "external" before the declaration of the method in the header,
I get the error message:
"storage class specified for 'freePolynomial'"So I have no idea what to do!
-
@Calivernon Did you check the link provided by SGaist? Templates MUST be defined in the header file. So, you cannot put the definition in a .cpp file.
-
Can you share your code ? Without it it's pretty much Crystal Ball Debugging.
-
It's alright, I started a new project and I don't really know why but it works now.
Thanks guys. -
That's a good news but still a strange mystery…
By the way, no need to modify the thread title, you can mark it as solved using the "Topic Tool" button :)