I'm running a Qt application that uses a lot of external libraries, and I'm forced to use CMake.

I'm compiled, linked and run a Qt application already. I can add a plot, and everything works. But when I try to add a marker I get linking errors. After hours lost, posting a question on stackoverflow , I cannot find out why. I reproduced the error using the curvdemo1.cpp example. I'm using Qt 4.8 (kept having issues with Qwt and Qt 5) and Qwt 6.1.2. The code is the same, I just did copy paste, and the CMakeLists.txt is as follows:

Qt Code:
  1. cmake_minimum_required(VERSION 2.8.11)
  2.  
  3. # Find includes in corresponding build directories
  4. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  5.  
  6. # Find the QtWidgets library
  7. find_package(Qt4 REQUIRED)
  8. INCLUDE(${QT_USE_FILE})
  9. # Find qwt
  10. find_path(QWTDIR qwt.h HINTS /usr/local/qwt-6.1.2/include)
  11. find_library(QWTLIBRARY qwt /usr/local/qwt-6.1.2/lib/)
  12. include_directories(${QWTDIR})
  13.  
  14. # source, header and resources files list
  15. set(CPP_SOURCES curvdemo1.cpp) #
  16.  
  17. # Generate moc files from cpp
  18. qt4_wrap_cpp(MOC_SOURCES ${CPP_SOURCES})
  19.  
  20. # Add compiler flags for building executables (-fPIE)
  21. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  22.  
  23.  
  24. # Tell CMake to create the helloworld executable
  25. add_executable(demo1 ${CPP_SOURCES} ${MOC_SOURCES})
  26.  
  27. #Link the helloworld executable to the Qt 5 widgets library.
  28. target_link_libraries(demo1 ${QT_LIBRARIES} ${QWTLIBRARY} Qt4::QtSvg)
To copy to clipboard, switch view to plain text mode 

The output of the compilation is:

Qt Code:
  1. >> make
  2. [ 33%] Generating moc_curvdemo1.cxx
  3. /home/jcolmenares/development/qwt/qwt-6.1.2/examples/curvdemo2/curvdemo1.cpp:0: Note: No relevant classes found. No output generated.
  4. Scanning dependencies of target demo1
  5. [ 66%] Building CXX object CMakeFiles/demo1.dir/curvdemo1.cpp.o
  6. [100%] Building CXX object CMakeFiles/demo1.dir/moc_curvdemo1.cxx.o
  7. Linking CXX executable demo1
  8. CMakeFiles/demo1.dir/curvdemo1.cpp.o: In function `MainWin::MainWin()':
  9. curvdemo1.cpp:(.text+0x2d4): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
  10. curvdemo1.cpp:(.text+0x343): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
  11. curvdemo1.cpp:(.text+0x46b): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
  12. curvdemo1.cpp:(.text+0x4d4): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
  13. curvdemo1.cpp:(.text+0x561): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
  14. curvdemo1.cpp:(.text+0x5ee): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
  15. curvdemo1.cpp:(.text+0x6b5): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
  16. curvdemo1.cpp:(.text+0x79e): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
  17. collect2: error: ld returned 1 exit status
  18. make[2]: *** [demo1] Error 1
  19. make[1]: *** [CMakeFiles/demo1.dir/all] Error 2
  20. make: *** [all] Error 2
  21. >>
To copy to clipboard, switch view to plain text mode