OpenCV 对 libQt5Core.so.5 的未定义引用

OpenCV 对 libQt5Core.so.5 的未定义引用

在开始之前,我想指出的是,实际上有一个非常相似(可能完全相同)的问题。但是,通过查看已接受的答案,我仍无法解决我的问题。

我按照本网站在 Ubuntu 16.04 上安装 OpenCV3。我尝试使用 g++ 编译一个测试程序(第 6 节)。编译返回以下内容:

/usr/bin/ld: warning: libicui18n.so.58, needed by //home/raggot/anaconda3/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuuc.so.58, needed by //home/raggot/anaconda3/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicudata.so.58, needed by //home/raggot/anaconda3/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `u_errorName_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_setMillis_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_getAlias_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_inDaylightTime_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `u_strToLower_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_getStandardName_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `u_strToUpper_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_setSubstChars_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_getMaxCharSize_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_getTimeZoneDisplayName_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_fromUnicode_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_open_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_getDefaultName_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_getDefaultTimeZone_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_clone_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_getDSTSavings_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucol_strcoll_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_close_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_countAvailable_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_openCountryTimeZones_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucol_open_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_compareNames_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_close_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_getAvailableName_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_openTimeZoneIDEnumeration_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_open_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucol_setAttribute_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_openTimeZones_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `uenum_close_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_countAliases_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucol_close_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucol_getSortKey_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucal_get_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `uenum_next_58'
//home/raggot/anaconda3/lib/libQt5Core.so.5: undefined reference to `ucnv_toUnicode_58'
collect2: error: ld returned 1 exit status

尝试申请回答我的问题,我尝试在我的系统上本地化 Qt5 的安装路径。我使用 做到了dpkg --listfiles libqt5core5a。我将结果路径添加到LD_LIBRARY_PATH,但没有帮助。

我尝试重新安装 Qt5sudo apt install qt5-default并且也安装了qttools5-dev但也没有帮助。

我的问题可能与编译器使用 anaconda 的库有关,而我实际上是在全局环境中工作。进一步的研究还表明,我使用的 Qt5 安装apt install版本为 5.5.1,而如果我输入,qtdiag则会看到版本 5.6.2。这可能是因为我可能在某个时候也在 anaconda 下安装了 Qt5。所以,我可能有 2 个安装。但我不知道如何验证这一点。

造成该问题的原因可能是什么?

编辑:

感谢评论,我意识到它anaconda3根本不应该在里面PATH。经过一番尝试,我发现它被添加到登录时的路径中.bashrc,可能是因为我在安装 Anaconda 时要求这样做。我将其删除并make再次尝试。

这就是我现在看到的(摘录很长的输出):

/usr/local/lib/libopencv_imgcodecs.so: undefined reference to `jpeg_stdio_dest@LIBJPEG_9.0'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QGraphicsView::staticMetaObject@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QSize::scaled(QSize const&, Qt::AspectRatioMode) const@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QWidget::update()@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QWidget::paintEngine() const@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QAbstractSlider::setMinimum(int)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QCheckBox::minimumSizeHint() const@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QFileInfo::QFileInfo(QString const&)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QWidget::hideEvent(QHideEvent*)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QObject::connectNotify(QMetaMethod const&)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `non-virtual thunk to QBoxLayout::hasHeightForWidth() const@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QWidget::isFullScreen() const@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QWidget::hasHeightForWidth() const@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QPen::QPen(QBrush const&, double, Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QStatusBar::showMessage(QString const&, int)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QObject::customEvent(QEvent*)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QObject::QObject(QObject*)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QFont::setLetterSpacing(QFont::SpacingType, double)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QGraphicsView::dragLeaveEvent(QDragLeaveEvent*)@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `typeinfo for QHBoxLayout@Qt_5'
/usr/local/lib/libopencv_highgui.so: undefined reference to `QGLWidget::~QGLWidget()@Qt_5'

这让我觉得我现在只是想念一些东西PATH

我在 的子文件夹中找到了这些库的定义位置(在我的 Qt5 安装中)/usr/include/x86_64-linux-gnu/qt5/,然后PATH通过export中的命令将它们全部添加到.profile,然后运行source .profile​​。如果我现在运行,echo $PATH我会看到它们都在原位。

不幸的是,如果我运行该命令,错误消息仍然相同make

编辑#2:

在将所有包含 Qt5 标题的子文件夹添加到后PATH,我尝试通过执行PATH以下操作添加一份副本LD_LIBRARY_PATH

export  LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PATH

然而,错误消息再次没有本质上的改变。我真的不明白为什么编译器看不到 Qt5 库。

答案1

简而言之:我通过从头开始重建 OpenCV 解决了这个问题。此解决方案归功于用户托马斯·波斯皮舍克

PATHOpenCV 的安装依赖于 Anaconda 的 Python3 安装和软件包,而不是 root。无论、PYTHONPATH或 的内容是什么LD_LIBRARY_PATH,也不管我是否已将anaconda文件夹重命名为anaconda_renamed以避免被发现,OpenCV 本身都是依赖于 Anaconda 的软件包构建的。毫不奇怪,此时它们没有被发现。

这个问题并不容易解决,即使我尝试使用标准cmake 安装说明OpenCV、Anaconda 依然最终走上了道路。但是,通过使用,并在字段中cmake-gui搜索,我设法找到了它的使用位置。anaconda

cmake经过多次尝试,通过将的字段链接到远离的字段来优雅地解决这个问题anaconda,并看到默认情况下 CMake 如何不断地在这里和那里找到 Anaconda 包,我最终从我的系统中删除了 Anaconda,提取了最新版本的opencv和,opencv-contrib并再次按照 OpenCV 的安装说明进行操作。

make过程导致一些 CUDA 软件包出现错误(例如cudaarithmcudatest)。使用它们从构建中排除是cmake-gui可行的。我希望我永远不会后悔这些排除。

附言:如果其他不幸的用户也发现他们的make -j4命令导致构建过程停留在 99% 数小时,请尝试make -j1

答案2

我遇到过不同的软件抱怨找不到 qt 文件,PATH 已设置为正确的 bin 目录,LD_LIBRARY_PATH 已设置为正确的 lib 目录。问题是 PATH 未指向 QT 的包含目录。我添加了包含目录和 include/Qt 目录。然后我在 opencv 上运行 configure 并进行 make。然后我的程序就可以编译了。

相关内容