Ed James
Ed James

Reputation: 10607

Linker issue: undefined reference

I have a problem with the linker when I build my current project.

The error it comes up with is as follows:

libmiinddynamic.so: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& SparseImplementationLib::operator<< <double, double, SparseImplementationLib::DefaultPtr<double, double> >(std::basic_ostream<char, std::char_traits<char> >&, SparseImplementationLib::AbstractSparseNode<double, double, SparseImplementationLib::DefaultPtr<double, double> > const&)'

This is slightly strange, as as far as I'm aware this method is declared in a file that is definitely being compiled:


namespace SparseImplementationLib {
        template <ActivityType,WeightType,ptr_type = 
DefaultPtr<ActivityType,WeightType> > class AbstractSparseNode;
    // A whole bunch of other methods

//! All derived classes from AbstractSparseNode can use operator<<
template <class ActivityType, class WeightType, class ptr_type>
ostream& operator<<
(
    ostream& s, 
    const AbstractSparseNode<ActivityType,WeightType>& node)
{
    node.ToStream(s);
    return s;
}

}

Why this error might pop up?

N.B. This is compiled using MPICXX on Fedora, and I'm using CCMAKE.

EDIT Ok, using nm I've found the following:

std::ostream& SparseImplementationLib::operator<< <double, double, SparseImplementationLib::DefaultPtr<double, double> >(std::ostream&, SparseImplementationLib::AbstractSparseNode<double, double, SparseImplementationLib::DefaultPtr<double, double> > const&)

when it wants this instead:

std::basic_ostream >& SparseImplementationLib::operator<< <double, double, SparseImplementationLib::DefaultPtr<double, double> >(std::basic_ostream >&, SparseImplementationLib::AbstractSparseNode<double, double, SparseImplementationLib::DefaultPtr<double, double> > const&)
Unfortunately, I have no idea how to fix this, cus operator<< only takes 2 arguments.

(The random \s before all the _s is to try and escape them, stackoverflow is being a little temperamental today and won't do it (otherwise we get lovely italics randomly in my code))

Upvotes: 2

Views: 386

Answers (2)

Mr.Ree
Mr.Ree

Reputation: 8418

Trying to parse (reformat) that line so I can read it...

libmiinddynamic.so: undefined reference to:
ostream & SparseImplementationLib::operator<<
   < double, double, SparseImplementationLib::DefaultPtr<double, double> >
(
   ostream &,
  SparseImplementationLib::AbstractSparseNode<
     double, double, SparseImplementationLib::DefaultPtr<double, double> > const
)

If I read that right, then:

  • class ActivityType is a double.
  • class WeightType is a double.
  • class ptr_type is a SparseImplementationLib::DefaultPtr<double, double>

And somehow the second argument
const AbstractSparseNode<ActivityType,WeightType>&,
e.g const AbstractSparseNode<double,double>&
has become a:

  SparseImplementationLib::AbstractSparseNode<
     double,
     double,
     SparseImplementationLib::DefaultPtr<double, double>
       > const &

The template argument counts don't match up. You've defined the second (templated) argument with 2 templated parameters and your error message indicates 3 templated parameters.

Upvotes: 0

user414441
user414441

Reputation:

can you nm the object which is generated by above shown code, to see that the signature is indeed what you expect.

Upvotes: 1

Related Questions