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:
cmake_minimum_required(VERSION 2.8.11)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the QtWidgets library
find_package(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
# Find qwt
find_path(QWTDIR qwt.h HINTS /usr/local/qwt-6.1.2/include)
find_library(QWTLIBRARY qwt /usr/local/qwt-6.1.2/lib/)
include_directories(${QWTDIR})
# source, header and resources files list
set(CPP_SOURCES curvdemo1.cpp) #
# Generate moc files from cpp
qt4_wrap_cpp(MOC_SOURCES ${CPP_SOURCES})
# Add compiler flags for building executables (-fPIE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Tell CMake to create the helloworld executable
add_executable(demo1 ${CPP_SOURCES} ${MOC_SOURCES})
#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(demo1 ${QT_LIBRARIES} ${QWTLIBRARY} Qt4::QtSvg)
cmake_minimum_required(VERSION 2.8.11)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the QtWidgets library
find_package(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
# Find qwt
find_path(QWTDIR qwt.h HINTS /usr/local/qwt-6.1.2/include)
find_library(QWTLIBRARY qwt /usr/local/qwt-6.1.2/lib/)
include_directories(${QWTDIR})
# source, header and resources files list
set(CPP_SOURCES curvdemo1.cpp) #
# Generate moc files from cpp
qt4_wrap_cpp(MOC_SOURCES ${CPP_SOURCES})
# Add compiler flags for building executables (-fPIE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Tell CMake to create the helloworld executable
add_executable(demo1 ${CPP_SOURCES} ${MOC_SOURCES})
#Link the helloworld executable to the Qt 5 widgets library.
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:
>> make
[ 33%] Generating moc_curvdemo1.cxx
/home/jcolmenares/development/qwt/qwt-6.1.2/examples/curvdemo2/curvdemo1.cpp:0: Note: No relevant classes found. No output generated.
Scanning dependencies of target demo1
[ 66%] Building CXX object CMakeFiles/demo1.dir/curvdemo1.cpp.o
[100%] Building CXX object CMakeFiles/demo1.dir/moc_curvdemo1.cxx.o
Linking CXX executable demo1
CMakeFiles/demo1.dir/curvdemo1.cpp.o: In function `MainWin::MainWin()':
curvdemo1.cpp:(.text+0x2d4): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
curvdemo1.
cpp:(.
text+0x343
): undefined reference to `
QwtPlotCurve::setPen(QColor const
&,
double, Qt
::PenStyle)'curvdemo1.cpp:(.text+0x46b): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
curvdemo1.
cpp:(.
text+0x4d4
): undefined reference to `
QwtPlotCurve::setPen(QColor const
&,
double, Qt
::PenStyle)'curvdemo1.cpp:(.text+0x561): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
curvdemo1.
cpp:(.
text+0x5ee
): undefined reference to `
QwtPlotCurve::setPen(QColor const
&,
double, Qt
::PenStyle)'curvdemo1.cpp:(.text+0x6b5): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
collect2: error: ld returned 1 exit status
make[2]: *** [demo1] Error 1
make[1]: *** [CMakeFiles/demo1.dir/all] Error 2
make: *** [all] Error 2
>>
>> make
[ 33%] Generating moc_curvdemo1.cxx
/home/jcolmenares/development/qwt/qwt-6.1.2/examples/curvdemo2/curvdemo1.cpp:0: Note: No relevant classes found. No output generated.
Scanning dependencies of target demo1
[ 66%] Building CXX object CMakeFiles/demo1.dir/curvdemo1.cpp.o
[100%] Building CXX object CMakeFiles/demo1.dir/moc_curvdemo1.cxx.o
Linking CXX executable demo1
CMakeFiles/demo1.dir/curvdemo1.cpp.o: In function `MainWin::MainWin()':
curvdemo1.cpp:(.text+0x2d4): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
curvdemo1.cpp:(.text+0x343): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
curvdemo1.cpp:(.text+0x46b): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
curvdemo1.cpp:(.text+0x4d4): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
curvdemo1.cpp:(.text+0x561): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
curvdemo1.cpp:(.text+0x5ee): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
curvdemo1.cpp:(.text+0x6b5): undefined reference to `QwtPlotCurve::setPen(QColor const&, double, Qt::PenStyle)'
curvdemo1.cpp:(.text+0x79e): undefined reference to `QwtPlotCurve::setSymbol(QwtSymbol*)'
collect2: error: ld returned 1 exit status
make[2]: *** [demo1] Error 1
make[1]: *** [CMakeFiles/demo1.dir/all] Error 2
make: *** [all] Error 2
>>
To copy to clipboard, switch view to plain text mode
Bookmarks