c++ - 编译时 OpenCV Qt undefined reference 错误

标签 c++ qt opencv cmake

我正在尝试使用深度传感器 (PMD Camboard) 并尝试将捕获的深度图像显示为实时流。我可以很好地从传感器获取数据。一旦我尝试放入 OpenCV 部件,问题就开始了。它们单独工作时完美无缺,但是当我尝试将它们集成时,问题就开始了。我认为错误出在 CMakeLists.txt,因为即使我尝试编译一个只显示网络摄像头源的简单程序,没有任何深度传感器的东西,我也会得到同样的错误。当我尝试仅使用 openCV 的 CMake 编译该程序时,该程序有效。

编辑:我尝试系统地禁用 CMake 的某些部分以查看哪些部分恰好触发了错误并发现该行:

link_directories(${royale_LIB_DIR})

是导致错误的原因。

当我尝试编译时出现以下错误:

    /usr/local/lib/libopencv_highgui.so.3.1.0: undefined reference to `QWidget::isFullScreen() const@Qt_5'
/usr/local/lib/libopencv_cvv.so.3.1.0: undefined reference to `QAbstractSlider::setMinimum(int)@Qt_5'
/usr/local/lib/libopencv_highgui.so.3.1.0: undefined reference to `non-virtual thunk to QBoxLayout::minimumSize() const@Qt_5'
/usr/lib64/libQt5OpenGL.so.5: undefined reference to `QTransform::type() const@Qt_5'
/usr/local/lib/libopencv_cvv.so.3.1.0: undefined reference to `QWidget::hasHeightForWidth() const@Qt_5'
/usr/lib64/libQt5OpenGL.so.5: undefined reference to `QPen::color() const@Qt_5'
/usr/local/lib/libopencv_cvv.so.3.1.0: undefined reference to `QFrame::changeEvent(QEvent*)@Qt_5'
/usr/lib64/libQt5OpenGL.so.5: undefined reference to `QOpenGLMultiGroupSharedResource::insert(QOpenGLContext*, QOpenGLSharedResource*)@Qt_5_PRIVATE_API'
/usr/lib64/libQt5OpenGL.so.5: undefined reference to `QPaintDevice::~QPaintDevice()@Qt_5'
/usr/local/lib/libopencv_cvv.so.3.1.0: undefined reference to `QObject::QObject(QObject*)@Qt_5'
/usr/local/lib/libopencv_cvv.so.3.1.0: undefined reference to `QTabWidget::metaObject() const@Qt_5'
/usr/local/lib/libopencv_cvv.so.3.1.0: undefined reference to `QColorDialog::QColorDialog(QWidget*)@Qt_5'
/usr/local/lib/libopencv_highgui.so.3.1.0: undefined reference to `QFutureInterfaceBase::setThreadPool(QThreadPool*)@Qt_5'
/usr/lib64/libQt5OpenGL.so.5: undefined reference to 

完整错误 http://pastebin.com/KLKtzzSn

而我的CMakeLists.txt如下:

cmake_minimum_required(VERSION 2.8)

set(CMAKE_PREFIX_PATH "share")

#project (depthDataCallBack)
project (webStream)

find_package(OpenCV REQUIRED)
find_package(royale REQUIRED)


link_directories(${royale_LIB_DIR})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)

add_executable(webStream webStream.cpp)

target_link_libraries(webStream ${OpenCV_LIBS})
target_link_libraries(webStream "${royale_LIBS}")

我是 CMake 的新手,之前只接触过 recently corrected .任何帮助将不胜感激。

最佳答案

错误列表显示链接中没有Qt5 Widgets。将以下行添加到您的 CMakeLists.txt:

target_link_libraries(webStream Qt5::Widgets)
target_link_libraries(webStream Qt5::Core)

另一个问题是该系统中是否安装了 Qt 5。 另请阅读此处:cmake doesn't link libGLU using QtOpenGL只要还缺少 Qt OpenGL 依赖项。

关于c++ - 编译时 OpenCV Qt undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41330498/

相关文章:

c++ - 嵌套容器上的 qDeleteAll

qt - PyQT5 错误 : could not find or load Qt platform plugin xcb

c++ - 在 Visual Studio 项目目录中找不到头文件

c++ - 是否需要私有(private)静态方法?

c++ - isdigit() c++,可能是简单的问题,但卡住了

c++ - 调用Qpainter的paint方法刷新图片,改变颜色

python - 无法让 cv.transform 工作

performance - 矩阵求逆的最快方法

opencv - 无法向 OpenCV 添加额外的模块(即使使用匹配版本的 opencv/opencv_contrib)

C++ Poco - 如何遍历 JSON 数组?