Доброго времени суток уважаемые эксперты. В моем приложении необходимо строить графики функций и гистограммы распределения. Покопавшись в интернете наткнулся на библиотеку qwt. Дабы не заморачиваться с установкой и настройкой последней версии библиотеки установил из репозиториев (у меня ubuntu 10.04) библиотеку 5-й версии. Копнув поглубже нашел простенький пример на Хабре (
http://habrahabr.ru/blogs/qt_software/82614/#habracut). Немного подправил файл проекта.
Было:
TEMPLATE = app
include(qwt.prf)
unix {
}
win32 {
LIBS += -L"D:/mydocs/qt4projects/qt4comp/qwt-5.2.0/lib" -lqwt
}
HEADERS = QwtBeginner.h
SOURCES = QwtBeginner.cpp \
main.cpp
Стало:
TEMPLATE = app
LIBS += -lqwt
HEADERS = QwtBeginner.h
SOURCES = QwtBeginner.cpp \
main.cpp
Попытался запустить а вместо программы получаю кучу сообщений типа:
/home/impuls/QwtBeginner/QwtBeginner.cpp:17: undefined reference to `QwtPlot::QwtPlot(QWidget*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:18: undefined reference to `QwtPlot::QwtPlot(QWidget*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:27: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:28: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:29: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:30: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:32: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:33: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:34: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:35: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:37: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:38: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:39: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:40: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:42: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:43: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:44: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:45: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:64: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:65: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:66: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:67: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:17: undefined reference to `QwtPlot::QwtPlot(QWidget*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:18: undefined reference to `QwtPlot::QwtPlot(QWidget*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:27: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:28: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:29: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:30: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:32: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:33: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:34: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:35: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:37: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:38: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:39: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:40: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:42: undefined reference to `QwtPlotCurve::QwtPlotCurve()'
/home/impuls/QwtBeginner/QwtBeginner.cpp:43: undefined reference to `QwtPlotItem::setRenderHint(QwtPlotItem::RenderHint, bool)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:44: undefined reference to `QwtPlotCurve::setPen(QPen const&)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:45: undefined reference to `QwtPlotItem::attach(QwtPlot*)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:64: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:65: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:66: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
/home/impuls/QwtBeginner/QwtBeginner.cpp:67: undefined reference to `QwtPlotCurve::setData(double const*, double const*, int)'
collect2: ld returned 1 exit status
А вот и сам код:
//-----------------------------------------------------------------
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
//-----------------------------------------------------------------
#include <qwt-qt4/qwt_plot.h>
#include <qwt-qt4/qwt_plot_curve.h>
//-----------------------------------------------------------------
#include <math.h>
//-----------------------------------------------------------------
#include "QwtBeginner.h"
//-----------------------------------------------------------------
QwtBeginner::QwtBeginner(QWidget *parent):QWidget(parent)
{
// Create plots
funPlot = new QwtPlot;
derPlot = new QwtPlot;
funPlot->setTitle("Function");
derPlot->setTitle("Derivative");
// Create curves and attach them to plots
QPen sinPen = QPen(Qt::red);
QPen cubPen = QPen(Qt::blue);
sinFunCurve = new QwtPlotCurve;
sinFunCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
sinFunCurve->setPen(sinPen);
sinFunCurve->attach(funPlot);
sinDerCurve = new QwtPlotCurve;
sinDerCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
sinDerCurve->setPen(sinPen);
sinDerCurve->attach(derPlot);
cubFunCurve = new QwtPlotCurve;
cubFunCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
cubFunCurve->setPen(cubPen);
cubFunCurve->attach(funPlot);
cubDerCurve = new QwtPlotCurve;
cubDerCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
cubDerCurve->setPen(cubPen);
cubDerCurve->attach(derPlot);
// Set data
const int N = 20;
double x[N+1];
double sinFunData[N+1], sinDerData[N+1];
double cubFunData[N+1], cubDerData[N+1];
for (int i = 0; i <= N; ++i)
{
const double pi = 4.0 * atan(1.0);
double L = 2;
double h = L / N;
x[i] = -L/2 + i * h;
sinFunData[i] = sin(x[i] * pi);
sinDerData[i] = cos(x[i] * pi) * pi;
cubFunData[i] = x[i] * x[i] * x[i];
cubDerData[i] = 3 * x[i] * x[i];
}
sinFunCurve->setData(x, sinFunData, N+1);
sinDerCurve->setData(x, sinDerData, N+1);
cubFunCurve->setData(x, cubFunData, N+1);
cubDerCurve->setData(x, cubDerData, N+1);
// Hide curves
sinFunCurve->setVisible(false);
sinDerCurve->setVisible(false);
cubFunCurve->setVisible(false);
cubDerCurve->setVisible(false);
// Create buttons
sinButton = new QPushButton("Sinus"),
cubButton = new QPushButton("Cubic function"),
sinButton->setCheckable(true);
cubButton->setCheckable(true);
// Connect signals
connect(sinButton, SIGNAL(toggled(bool)), this, SLOT(sinToggled(bool)));
connect(cubButton, SIGNAL(toggled(bool)), this, SLOT(cubToggled(bool)));
// Set layouts
QHBoxLayout *plotsLayout = new QHBoxLayout;
plotsLayout->setSpacing(10);
plotsLayout->addWidget(funPlot);
plotsLayout->addWidget(derPlot);
QHBoxLayout *buttonsLayout = new QHBoxLayout ;
buttonsLayout->addWidget(sinButton);
buttonsLayout->addWidget(cubButton);
QVBoxLayout *widgetLayout = new QVBoxLayout;
widgetLayout->addLayout(plotsLayout);
widgetLayout->addLayout(buttonsLayout);
setLayout(widgetLayout);
showMaximized();
}
//-----------------------------------------------------------------
void QwtBeginner::sinToggled(bool checked)
{
sinFunCurve->setVisible(checked);
sinDerCurve->setVisible(checked);
funPlot->replot();
derPlot->replot();
}
//-----------------------------------------------------------------
void QwtBeginner::cubToggled(bool checked)
{
cubFunCurve->setVisible(checked);
cubDerCurve->setVisible(checked);
funPlot->replot();
derPlot->replot();
}
//-----------------------------------------------------------------
Собственно хотелось бы узнать причину такой ненависти компилятора к данной библиотеке)))
Расскажите что я не так делаю, и, если можно, помогите примерами пользования данной библиотекой (ибо под 5 версию я экземплов не нашел)
Заранее спасибо за помощь.
З.Ы. Извиняюсь что такое обширное сообщение: не нашел как вставлять спойлеры.