Reputation: 131
I am having an unusual error when trying to compile my project in Qt Creator 2.4.1. It compiles out just fine until it needs to link my code and it says "Undefined refernce to 'XXX'" Where "XXX" is a file that it compiled just fine and I wrote so I know that the functions it can't seem to find exist. Here is an example (just in case what I just described doesn't make sense): undefined reference to `ESanity NSane::CSane::ArgumentCheck(int)'
Here is the code I wrote and compiled just fine:
Declaration (in class)
template<typename Type> ESanity ArgumentCheck(Type aObj);
Definition (in source)
template<typename Type>
ESanity CSane::ArgumentCheck(Type aObj)
{
assert(aObj != NULL);
return aObj != NULL ? ESanity_Sane : ESanity_Insane;
}
Qt Creator (I guess it is technically g++, Qt Creator is just an IDE) says that it can't link to it's own compiled source and it also says when I double-click the error in the error window, that the file is missing even though it opens and I can see it.
PLEASE NOTE: I am compiling on Xubuntu 12.04 LTS with Qt Creator 2.4.1 using g++ 4.6.3
Upvotes: 1
Views: 244
Reputation: 45410
It's template code, you can't separate definition into .cpp, you have to put all code in one file
Upvotes: 1