I am building a library that handles several different types of binary "languages", which has a "Processor" type for each language. The library builds fine, and I've narrowed down the issue so far to the following template code:
// Processor.h
template <class A, class B = DefaultProcessor>
class Processor
{
public:
// Default constructor.
Processor(void);
// Constructor from DefaultProcessor pointer type.
Processor(B* pB);
virtual ~Processor(void){};
// Dereferencing operator
A* operator->(void) const;
private:
A* pRawPointer;
};
// Processor.cpp
template <class A, class B>
A* Processer<A, B>::operator->(void) const
{
if (nullptr == pRawPointer)
{
throw();
}
return pRawPointer;
}
// Constructor from DefaultProcessor pointer type.
template <class A, class B>
Processor<A, B>::Processor(B* pB)
: pRawPointer(dynamic_cast<A*>(pB))
{
}
I have dozens of different classes it supports, and in my library, I have a long list of explicit instantiations:
template class Processor<CustomType1>;
template class Processor<CustomType2>;
template class Processor<CustomType3>;
template class Processor<CustomType1, CustomType2>;
template class Processor<CustomType4>;
template class Processor<CustomType5>;
template class Processor<CustomType6>;
When I attempt to build an application that links against my library, I encounter the following errors when compiling via g++ -Wall -std=c++11
, but doesn't have any issues building in Visual Studio 2015:
undefined reference to `Processor<CustomType4, DefaultProcessor>::Processor(DefaultProcessor*)'
undefined reference to `Processor<CustomType4, DefaultProcessor>::operator->() const'
undefined reference to `Processor<CustomType5, DefaultProcessor>::Processor(DefaultProcessor*)'
undefined reference to `Processor<CustomType5, DefaultProcessor>::operator->() const'
It's almost as if the explicit instantiations aren't being completely generated when building in Linux. I've tried explicitly instantiating in the library via:
template class Processor<CustomType4, DefaultProcessor>;
template class Processor<CustomType5, DefaultProcessor>;
This just causes the library to fail to build due to duplicate explicit instantiations.
What would cause this issue to arise solely in Linux builds?
Thank you.