我通常使用CMake和本地环境在Ubuntu上工作。我的项目编译并运行良好。现在我改为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>
)
答案 0 :(得分:0)
CMakeLists.txt缺少
行target_link_libraries(libQCustomPlot Qt5::Widgets)
请参阅Qt documentation on compiling with CMake。此外,除非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未在未定义引用上失败的更多详细信息,请参见in this question。
警告是关于覆盖另一个函数的函数中缺少override specifier。以下将避免警告:
virtual int findEnd(double sortKey, bool expandedRange=true) const override;