I’ve created (in Qt and Mingwin the specified case), a class that has the following structure:
#ifndef POINT2D_H
#define POINT2D_H
#include "Calculus_global.h"
#include <QtCore>
namespace Calculus
{
/** Class for definition of a point in 2D space */
class CALCULUSSHARED_EXPORT CartesianPoint2D
{
public:
//! Constructor
CartesianPoint2D();
//! Set x value
void setX(const qreal &qrX);
// ETC ETC ETC
};
} // namespace Calculus
///////////////////////////////////////////////////////////////////////////////
// RELATED NON-MEMBER OPERATORS //
///////////////////////////////////////////////////////////////////////////////
//! Addition operator
Calculus::CartesianPoint2D operator +(const Calculus::CartesianPoint2D &xAPoint, const Calculus::CartesianPoint2D &xBPoint);
//! Subtraction operator
Calculus::CartesianPoint2D operator -(const Calculus::CartesianPoint2D &xAPoint, const Calculus::CartesianPoint2D &xBPoint);
// And so on...
#endif // POINT2D_H
When I use this library, class methods works well. But when I want to use an operator, I got the undefined reference error, for example:
path\sources\testcalculus.cpp:273: error: undefined reference to `operator+(Calculus::CartesianPoint2D const&, Calculus::CartesianPoint2D const&)'
What I must do to export also the overloaded operators and use them?
Thanks for your replies.
You have to use CALCULUSSHARED_EXPORT in your free functions (the operators in this case) too. This (I think) is true only to Windows.