Reputation: 3410
I'm pretty new to C++ and I'm trying to compile my code. The command I'm using is g++ -o main --std=c++11 main.cpp channel.cpp
. However I'm getting the following error message:
/tmp/ccLuJs81.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `gsc::Channel<int>::Channel()'
main.cpp:(.text+0x3a): undefined reference to `gsc::Channel<int>::put(int)'
main.cpp:(.text+0x4e): undefined reference to `gsc::Channel<int>::get(bool)'
collect2: error: ld returned 1 exit status
Does anyone know what's going on here? Thanks a lot!
Upvotes: 0
Views: 921
Reputation: 154025
Seems you declared a template in a header and defined it in a C++ file. This won't work. If you don't define your template in a header, you need to explicitly instantiate it in your C++ file, e.g. ,using
template class gcs::Channel<int>;
after the definition of all the methods.
Upvotes: 6