I'm experiencing a linking error that I can't understand, and that only happens to some developers (maybe because we are using some different library or compiler versions):
undefined reference to `CodeAttributes::AddCodeAttribute(boost::variant<boost::blank, A, B, C > const&)'
The whole problematic class and function are kind of simple, but I can't make a self contained example because of the dependencies on other classes.
This is the declaration of the class:
class CodeAttributes : public SomeMixinClass<CodeAttributes>
{
public:
CodeAttributes();
CodeAttributes(const CodeAttribute& codeAttribute);
void AddCodeAttribute(const CodeAttribute& codeAttribute);
CodeAttribute GetCodeAttribute() const;
// other stuff
Then the CodeAttribute
type is a typedef like this:
typedef boost::variant<boost::blank, A, B, C> CodeAttribute;
And the implementation is again pretty simple:
void CodeAttributes::AddCodeAttribute(const CodeAttribute& codeAttribute)
{
m_CodeAttribute = codeAttribute;
}
CodeAttribute CodeAttributes::GetCodeAttribute() const
{
return m_CodeAttribute;
}
CodeAttributes::CodeAttributes(const CodeAttribute& codeAttribute)
: m_CodeAttribute(codeAttribute)
{}
CodeAttributes::CodeAttributes()
: m_CodeAttribute(boost::blank())
{}
The class gets compiled as a static library, and I get the above linking error when using the function from the unit tests of the project, which is using the static library to build an executable program. The function call is like this:
CodeAttributesPtr x(new CodeAttributes);
x->AddCodeAttribute(A());
I don't know which the problem could be, but I've tried the following:
- If I comment out the call to the setter function, it links correctly, so there seems to be only one problematic function: the setter. The getter is fine.
- Since I'm a bit lost, I tried calling the function some other way, like
x->AddCodeAttribute(x->GetCodeAttribute());
or passingboost::blank()
orCodeAtrribute(boost::blank())
. It still fails linking the same way. - I know little about libraries or object code, but I tried running
objdump
on the object code and the static library. I've found that the function exists, but theCodeAttribute
argument is a boost::variant with the template arguments of the definition (as expected), but followed by manyboost::detail::variant::void_
arguments which are not in the typedef. I don't know if this is just an implementation detail ofboost::variant
, but it seems to be the same type as the getter function, so is probably fine?
I don't know what else I could look at to find out which and where is the problem.