Oct 27, 2012 at 3:12am UTC
Hi, I get this error when I try to compile my code. Unfortunately I can't post it since its a hw assignment. Could someone explain what it means?
2 3 4
/tmp/ccmd73ST.o:main.cpp:(.text+0x13d): undefined reference to `HashMap<std::basic_string<
char, std::char_traits< char>, std::allocator< char> >, int>::HashMap() '
/tmp/ccmd73ST.o:main.cpp:(.text+0x14b): undefined reference to `HashMap<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::~HashMap()'
collect2: ld returned 1 exit status
Last edited on
Oct 27, 2012 at 4:03am UTC
Oct 27, 2012 at 6:04am UTC
Have you included all the necessary header files?
Have you linked all the libraries needed?
Have missed compiling one of your source files?
Is it a something from the std namespace that is missing the leading std:: ?
Oct 27, 2012 at 3:38pm UTC
Okay I did a template class and separated each part into .cpp and .h and In int main() i did #include".h" however I kept getting the error so I did #include".cpp" and it works fine. I dont understand why but it works.
Oct 27, 2012 at 3:41pm UTC
You will want to include the .h in the corresponding .cpp file.
template.cpp -> include template.h
main.cpp -> include template.h
template.h -> include .h files of any extra libraries being used ie - #include <hash_map> (it looks you are creating you own version)
You might want to consider using a makefile if you have several files to compile.
Last edited on
Oct 27, 2012 at 3:47pm UTC