Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
链接到CMake中的Qt-->;无法链接到QML/QtQuick函数_Qt_Ubuntu_Cmake_Qml_Qtquick2 - Fatal编程技术网

链接到CMake中的Qt-->;无法链接到QML/QtQuick函数

链接到CMake中的Qt-->;无法链接到QML/QtQuick函数,qt,ubuntu,cmake,qml,qtquick2,Qt,Ubuntu,Cmake,Qml,Qtquick2,我们正在将一个相当大的代码库从Ubuntu 14.04迁移到16.04。代码库使用QML和QtQuick 我们在依赖项中使用QtV5.9.1(与系统中安装的Qt版本不同) 编译时,我们有以下未定义的引用: /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1: undefined reference to `qrand()@Qt_5' /home/onilsson/DevRoot/D

我们正在将一个相当大的代码库从Ubuntu 14.04迁移到16.04。代码库使用QML和QtQuick

我们在依赖项中使用QtV5.9.1(与系统中安装的Qt版本不同)

编译时,我们有以下未定义的引用:

/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `qrand()@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to
`QAccessibleTextUpdateEvent::~QAccessibleTextUpdateEvent()@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QByteArray::mid(int, int) const@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QPainter::setOpacity(double)@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Qml.so.5.9.1:
undefined reference to `QXmlStreamReader::isCDATA() const@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QAnimationDriver::start()@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Qml.so.5.9.1:
undefined reference to `QLocale::toDate(QString const&, QString
const&) const@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QMetaType::unregisterConverterFunction(int,
int)@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QNetworkReply::finished()@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QMetaType::typeName(int)@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Qml.so.5.9.1:
undefined reference to `QXmlStreamReader::documentEncoding()
const@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QChar::toUpper(unsigned int)@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QTouchEvent::TouchPoint::state() const@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Quick.so.5.9.1:
undefined reference to `QElapsedTimer::start()@Qt_5'
/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/libQt5Qml.so.5.9.1:
undefined reference to `QDateTime::operator==(QDateTime const&)
const@Qt_5'
。。。它将永远持续下去。错误仅出现在Qml/QtQuick函数中,而不出现在其他模块中(例如QtCore、QtWidgets…不输出错误)

因此,我们已经检查了CMakeLists.txt,下面是Qt链接的方式:

set(CMAKE_INCLUDE_CURRENT_DIR ON) # Find includes in corresponding    build directories. set(CMAKE_AUTOMOC ON) # Instruct CMake to run moc    automatically when needed.
set(QT_DIR ../../Dependencies/Qt/v5.9.1/5.9.1/gcc_64)
set(CMAKE_PREFIX_PATH ${QT_DIR})

find_package(Qt5Widgets        REQUIRED)
find_package(Qt5Core           REQUIRED)
find_package(Qt5Gui            REQUIRED)
find_package(Qt5OpenGL         REQUIRED)
find_package(Qt5Quick          REQUIRED)
find_package(Qt5Qml            REQUIRED)
find_package(Qt5QuickControls2 REQUIRED)

target_link_libraries(${PROJECT_NAME}
     ...
     Qt5::Widgets
     Qt5::Core
     Qt5::Gui
     Qt5::OpenGL
     Qt5::Quick
     Qt5::Qml
     Qt5::QuickControls2 )
仔细查看CMake输出时,我们得到:

   Cannot generate a safe runtime search path for target ToolKitApp
because    files in some directories may conflict with libraries in
implicit    directories:

     runtime library [libQt5Sql.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
       /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib
     runtime library [libQt5OpenGL.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
       /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib
     runtime library [libQt5Widgets.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
       /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib
     runtime library [libQt5Gui.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
       /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib
     runtime library [libQt5Network.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
       /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib
     runtime library [libQt5Core.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
       /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib

   Some of these libraries may not be found correctly.
因此,Qt的系统版本和我们在依赖项中使用的版本之间似乎存在不匹配,我们认为这是罪魁祸首

因此,我们修改了CMakeLists.txt,添加了set(Qt5_DIR)…:

但这并没有改善情况

知道发生了什么吗

--------------编辑-----------------

我们对CMakeLists.txt进行了以下修改

set(CMAKE_PREFIX_PATH   /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64)
find_package(Qt5 COMPONENTS Core Gui OpenGL Quick QmlQuickControls2)

message("Qt5               : " Qt5_DIR)
message("Qt5Core           : " Qt5Core_DIR)
message("Qt5Widgets        : " Qt5Widgets_DIR)
message("Qt5Gui            : " Qt5Gui_DIR)
message("Qt5OpenGL         : " Qt5OpenGL_DIR)
message("Qt5Quick          : " Qt5Quick_DIR)
message("Qt5Qml            : " Qt5Qml_DIR)
message("Qt5QuickControls2 : " Qt5QuickControls2_DIR)
这并没有改变行为,而是输出

Qt5               : /usr/lib/x86_64-linux-gnu/cmake
Qt5Core           : /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/cmake
Qt5Widgets        : /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/cmake
Qt5Gui            : /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/cmake
Qt5OpenGL         : /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64/lib/cmake
Qt5Quick          : /usr/lib/x86_64-linux-gnu/cmake
Qt5Qml            : /usr/lib/x86_64-linux-gnu/cmake
Qt5QuickControls2 : /usr/lib/x86_64-linux-gnu/cmake

这确认了Qt的系统/软件包版本与自定义/依赖项版本之间存在不匹配,但未提供解决方案。

根据您的输出,我猜您有以下设置:

  • 您已经通过软件包管理器安装了一些(但不是全部)Qt5库(包括开发文件)
  • 但是,您可能没有安装QtQuick(开发)库
  • 此外,您在
    /home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/
    中安装了Qt(我想是通过官方Qt安装程序安装的)
  • 我猜你在家里试图编译和链接Qt版本
我认为您配置项目的方式(即调用
cmake
)有问题,因为CMake首先在你的系统位置搜索QT,并且在你的代码中设置了一些变量> CMAKLISTS.TXT 文件,这迫使它也考虑了在你的主目录中的安装-有选择地链接到其他QT安装的快速库。这肯定会导致此类链接器错误,特别是如果系统Qt版本比您在家中安装的版本旧

长话短说:您是否尝试在命令行上通过
CMake\u PREFIX\u PATH
变量调用CMake?在你的例子中,我想应该是这样的:

cmake \
    -DCMAKE_PREFIX_PATH=/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64 \
    ..

设置
Qt5Core\u DIR
和类似设置绝对不是必需的。根据我对Qt和CMake的经验,当您需要设置它们时,您的设置有问题。

正如Martin所说,CMake似乎链接到新系统中的库,而不是从旧系统移植的库。此外,您的新系统通过Ubuntu/Debian Aptitude软件包管理器安装了Qt库,并且缺少qtdeclarative5 dev和qml模块软件包(您可以使用sudo apt install qtdeclarative5 dev qtquick*在Ubuntu上安装它们)。
我猜CMake没有链接到您的移植库的原因可能是所有权问题。您是否尝试使用父目录中的“ls-lah”命令检查所有权。所有权现在可能分配给根目录,您可以使用“sudo chown-R username:group Directory”命令更改它。

Martin,谢谢您的回答。阅读你的评论,你的分析看起来不错。我今天无法检查你的建议,但我明天会尝试一下。同时,您建议从命令行设置CMAKE_PREFIX_PATH,尽管我们在CMakeLists.txt中设置了它,但命令行语句是否更强大?据我所知:是。在CMake中,有一些变量需要在配置过程的早期设置。这些变量需要通过
-D
开关或通过a从外部设置。我们已经从命令行设置了CMAKE_PREFIX_路径,但这并没有改变行为。虽然我们已经在消息中打印了Qt5Core_DIR和类似内容,并且输出似乎证实了您的分析(检查后期编辑)。这种奇怪的行为是否是由于另一个依赖项也在使用Qt,但Qt的系统/包(不是我们的自定义/依赖项版本)和创建这种不匹配?肯定是的。不支持混合不同的Qt版本,除其他奇怪的影响外,还可能导致此类链接错误。尝试编译您对自定义Qt版本的所有依赖项。我已使用sudo apt install qtdeclarative5 dev qtquick/asterisk**安装了其他软件包,但它似乎没有改变任何内容。。。我们还检查了依赖项的所有权,它们都设置为**onilsson:onilsson。哼
cmake \
    -DCMAKE_PREFIX_PATH=/home/onilsson/DevRoot/Dependencies/Qt/v5.9.1/5.9.1/gcc_64 \
    ..