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?
/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
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:: ?

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.
You will want to include the .h in the corresponding .cpp file.

For instance:

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
Topic archived. No new replies allowed.