如何为 OSX 编译 QCustomPlot



我通常在Ubuntu上工作,使用CMake和本机环境。我的项目编译并运行良好。现在我改用OSX,首先在编译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;

我想我可以抑制这个警告。然而,我不喜欢压制警告,如果它们可能意味着真正的危险。(在 Ubuntu 下,没有警告)。为什么是警告?我认为覆盖虚拟函数并不罕见或危险。

无论如何,有警告,但占主导地位。真正的问题出现在链接上

[  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

这里有什么问题?(由于使用多平台开发环境,我没想到会有任何丢失的文件、组件或类似问题。

编辑:这是生成它的CMake文件

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>
)

CMakeLists.txt 缺少该行

target_link_libraries(libQCustomPlot Qt5::Widgets)

请参阅有关使用 CMake 进行编译的 Qt 文档。此外,除非 CMakeLists.txt 需要支持 3.0 之前的 CMake 版本,否则可以删除其当前内容的很多内容。它可以简化为这样:

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>
)

有关GCC在未定义引用上不失败的更多详细信息,请参阅此问题。

该警告是关于重写另一个函数的函数中缺少的替代说明符。以下内容将避免警告:

virtual int findEnd(double sortKey, bool expandedRange=true) const override;

相关内容

  • 没有找到相关文章

最新更新