【发布时间】:2018-09-04 15:55:44
【问题描述】:
我正在尝试使用 Qt5 和 CMake 编写一个 GUI 应用程序(在 Ubuntu 18.04 下)。我未能将 Qt 多媒体模块集成到我的项目中。
我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(Chess)
#set(CMAKE_PREFIX_PATH "/home/mashplant/Qt5.9.6/5.9.6/gcc_64")
#whether I comment it off or not doesn't have an effect on the result
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets Network Multimedia REQUIRED)
set(CMAKE_CXX_STANDARD 11)
include_directories(.)
add_executable(Main Main.cpp
MainWindow.cpp MainWindow.hpp ChessFrame.cpp ChessFrame.hpp resource.qrc)
target_link_libraries(Main Qt5::Widgets Qt5::Network Qt5::Multimedia)
我在运行 CMake 时收到以下警告:
CMake Warning at CMakeLists.txt:18 (add_executable):
Cannot generate a safe runtime search path for target Main because files in
some directories may conflict with libraries in implicit directories:
runtime library [libQt5Widgets.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
runtime library [libQt5Network.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
runtime library [libQt5Gui.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
runtime library [libQt5Core.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
Some of these libraries may not be found correctly.
当我编译时,我得到一个链接错误。
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib/libQt5Multimedia.so.5.9.6:undefined reference to ‘operator delete(void*, unsigned long)@Qt_5’
collect2: error: ld returned 1 exit status
CMakeFiles/Main.dir/build.make:203: recipe for target 'Main' failed
make[3]: *** [Main] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Main.dir/all' failed
make[2]: *** [CMakeFiles/Main.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/Main.dir/rule' failed
make[1]: *** [CMakeFiles/Main.dir/rule] Error 2
Makefile:118: recipe for target 'Main' failed
make: *** [Main] Error 2
【问题讨论】:
-
问题不在于多媒体 QT 组件,而在于一般的 QT。您的系统上安装了 2 个 QT:系统一个,在
/usr/lib/x86_64-linux-gnu下,您自己的一个,在/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib下。但是 CMake 无法为链接器生成命令行,因此它可以选择正确的 QT 安装。这是因为系统和您的目录中的库都在您的项目中使用。如果要使用 QT 安装,请删除系统范围的安装。在新尝试之前不要忘记清除 CMake 缓存(构建目录中的CMakeCache.txt文件)。 -
@Tsyvarev 但是在以前的一些没有多媒体的项目中,它运行良好。这就是为什么我想知道如何整合多媒体。
-
@MashPlant 它可能是偶然工作的。如果您在这些项目中也没有从 CMake 收到相同的警告,我会感到非常惊讶(甚至 QtCore 似乎也存在冲突)。您可以尝试使用此选项
-DQt5_DIR=/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib/cmake/Qt5发布 CMake 吗?