2

I get an error

undefined reference to `QwtPlot::QwtPlot(QWidget*)'

when I try to build my project even though everything seems fine in the setup.

In my CmakeLists.txt I have

include_directories(
  [...]
  ${QWT_INCLUDE_DIR})

which points to where I have my Qwt headers and

find_package(Qwt REQUIRED)

works because QWT_FOUND is set to True

Here's my FindQwt.cmake:

#MESSAGE("Searching for QWT")
FIND_PATH(QWT_INCLUDE_DIR NAMES qwt.h PATHS
  /usr/include
  /usr/local/include
  "$ENV{LIB_DIR}/include" 
  "$ENV{INCLUDE}" 
  PATH_SUFFIXES qwt-qt4 qwt
  )

FIND_LIBRARY(QWT_LIBRARY NAMES qwt qwt5 qwt-qt4 qwt5-qt4 PATHS 
  /usr/lib
  /usr/local/lib
  "$ENV{LIB_DIR}/lib" 
  "$ENV{LIB}/lib" 
  )

IF (QWT_INCLUDE_DIR AND QWT_LIBRARY)
  SET(QWT_FOUND TRUE)
ENDIF (QWT_INCLUDE_DIR AND QWT_LIBRARY)

IF (QWT_FOUND)
  IF (NOT QWT_FIND_QUIETLY)
    MESSAGE(STATUS "Found QWT: ${QWT_LIBRARY}")
  ENDIF (NOT QWT_FIND_QUIETLY)
ELSE (QWT_FOUND)
  IF (QWT_FIND_REQUIRED)
    MESSAGE(FATAL_ERROR "Could not find QWT")
  ENDIF (QWT_FIND_REQUIRED)
ENDIF (QWT_FOUND)

Using message to print ${QWT_INCLUDE_DIR} points to qwt_plot.h, which has QwtPlot::QwtPlot(QWidget*) defined, so I'm not sure what I could be missing.

Shadow0144
  • 123
  • 2
  • 9
  • 1
    `undefined reference` means that *declaration of the symbol has been found* (in header file), but **definition is absent** (no library defines given symbol). You need to check value of `QWT_LIBRARY` variable and whether you actually use it for linking (`target_link_libraries`). – Tsyvarev Oct 25 '16 at 09:49
  • It seems to be finding the library just fine: message("Library: " ${QWT_LIBRARY}) returns "Library: /usr/lib/libqwt.so" But thank you for pointing that out, that makes sense! – Shadow0144 Oct 25 '16 at 10:03

1 Answers1

2

I forgot to actually link the library to the project

target_link_libraries(project
   [...]
   ${QWT_LIBRARY}
 )
Shadow0144
  • 123
  • 2
  • 9