-1

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>
)
2
  • I would really be glad, if before/after/instead/in_addition_to downvoting, you would leave a comment, why. Commented Jan 2, 2017 at 10:03
  • I did not downvote, but I think you should provide more details about the error: Run "make VERBOSE=1" instead of "make" to see what libraries are being linked to. In particular look for Qt5Core, which should be the one containing qt_assert_x. Can you successfully build something with qmake? For example, the QCustomPlot examples? The warning is nothing to worry about; it is suggesting to use the override specifier, which was introduced in C++11. But I guess QCustomPlot keeps compatibility with older C++. If you don't need C++11, then set (CMAKE_CXX_STANDARD 98) should remove the warning. Commented Jan 4, 2017 at 16:39

1 Answer 1

0

The CMakeLists.txt is missing the line

target_link_libraries(libQCustomPlot Qt5::Widgets)

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:

set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Core Widgets PrintSupport REQUIRED)

include_directories(include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -W -Wall")

ADD_LIBRARY(libQCustomPlot
    qcustomplot.cpp
)

set_target_properties(libQCustomPlot
                      PROPERTIES OUTPUT_NAME QCustomPlot
                      )

target_link_libraries(libQCustomPlot Qt5::Widgets)

target_include_directories(libQCustomPlot PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

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:

virtual int findEnd(double sortKey, bool expandedRange=true) const override;
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the detailed explanation. I did not search in this direction, because the same CMake file compiles, links and runs under Ubuntu.
If I omit ${Qt5Widgets_INCLUDE_DIRS} from include_directories(), I receive error message QtCore/qglobal.h not found. If I remove QT5_WRAP_CPP(qcustomplot_moc include/qcustomplot.h), I receive error messages of type undefined reference to vtable for QCPCurve'.
What is your CMake version? If you do not remove anything, but just add the target_link_libraries line, does everything compile?
cmake version 3.5.1
If this missing include file happens even when you have the target_link_libraries line, then this is strange. You may try if it is possible to compile some simple Qt example using the CMakeLists.txt file from the Qt documentation link that I provided in the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.