I am usually working on Ubuntu, using CMake and native environment. My project compiles and runs fine. Now I changed to OSX and first of all I receive some warnings when compiling QCustomPlot:
QCustomPlot/include/qcustomplot.h:6007:15: warning:
'findEnd' overrides a member function but is not marked 'override'
[-Winconsistent-missing-override]
virtual int findEnd(double sortKey, bool expandedRange=true) const;
^
../QCustomPlot/include/qcustomplot.h:3830:15: note:
overridden virtual function is here
virtual int findEnd(double sortKey, bool expandedRange=true) const = 0;
I suppose I can suppress this warning. I do not like, however, to suppress warnings, if they can mean a real danger. (under Ubuntu, there is no warning). Why is it a warning? I think to override a virtual function is not really unusual or dangerous.
Anyhow, with warnings, but dompiles. The real problem appears with linking
[ 4%] Building CXX object QCustomPlot/CMakeFiles/libQCustomPlot.dir/libQCustomPlot_automoc.cpp.o
[ 5%] Linking CXX shared library libQCustomPlot.dylib
Undefined symbols for architecture x86_64:
"qt_assert_x(char const*, char const*, char const*, int)", referenced from:
QList<QCPDataRange>::at(int) const in qcustomplot.cpp.o
QList<QCPDataRange>::operator[](int) in qcustomplot.cpp.o
What is the problem here? (as using a multiplatform development environment, I did not expect any missing file, component, or similar problem.)
Edit: here goes the CMake file that produced it
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Core Widgets PrintSupport REQUIRED)
include_directories(
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Printer_INCLUDE_DIRS}
include
)
add_definitions(${Qt5Widgets_DEFINITIONS} ${Qt5Printer_DEFINITIONS})
QT5_WRAP_CPP(qcustomplot_moc include/qcustomplot.h)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS} -std=c++11 -Wall")
ADD_LIBRARY(libQCustomPlot
qcustomplot.cpp
${qcustomplot_moc} # The MOC headers, generated
)
set_target_properties(libQCustomPlot
PROPERTIES OUTPUT_NAME QCustomPlot
)
target_include_directories(libQCustomPlot PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
The CMakeLists.txt is missing the line
See the Qt documentation on compiling with CMake. In addition, unless the CMakeLists.txt needs to support CMake versions older than 3.0, a lot of its current contents can be removed. It can be reduced to something like this:
More details about GCC not failing on undefined references can be found in this question.
The warning is about a missing override specifier in a function that overrides another function. The following will avoid the warning: