Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Undefined reference to 'QwtPlot::QwtPlot(QWidget*)'

 

link error.

 

 

 

 

 

Full error message

 

/MyFolder/main.o:: In function 'main': /MyFolder/main.cpp:8: error: undefined reference to 'QwtPlot::QwtPlot(QWidget*)' :: error: collect2: ld returned 1 exit status

 

 

 

 

 

Cause

 

Operating system: Ubuntu 10.04 LTS Lucid Lynx

IDE: Qt Creator 2.0.0

Project type: Console Application

Compiler: G++ 4.4.1

Libraries used:

 

 

 

 

 

Qt project file

 

#-------------------------------------------------
#
# Project created by QtCreator 2010-07-21T19:21:43
#
#-------------------------------------------------
QT += core gui
TARGET = CppQwtExample1
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L/usr/local/lib -lqwt

 

 

 

 

 

Source code

 

#include <QApplication>

#include <qwt-qt4/qwt_plot.h>

int main(int argc, char **argv)
{
  QApplication a(argc, argv);
  QwtPlot plot;
  plot.show();
  return a.exec();
}

 

 

 

 

 

Solution

 

Do not link to qwt, but to qwt-qt. You will also need to link to QtSvg (otherwise the Undefined reference to 'QGraphicsItemPrivate::height() const' link error occurs).

 

Change the Qt Creator project file to the following:

 

#------------------------------------------------- # # Project created by QtCreator 2010-07-21T19:21:43 # #------------------------------------------------- QT += core gui TARGET = CppQwtExample1 TEMPLATE = app SOURCES += main.cpp LIBS += -L/usr/local/lib -lqwt-qt4 LIBS += -L/usr/local/lib -lQtSvg

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict