gpt4 book ai didi

c++ - 如何使用 CMake 将 QtMultimedia 组件集成到项目中?

转载 作者:太空宇宙 更新时间:2023-11-04 12:01:41 27 4
gpt4 key购买 nike

我正在尝试使用 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

最佳答案

我最好的选择是 CMake 从不同的 Qt 安装中找到不同的组件。如果是这种情况,应该足以纠正所有与 Qt 相关的 CMake 变量以指向正确的路径(例如,Qt5Widgets_DIRQt5Multimedia_DIR 等变量)。

关于c++ - 如何使用 CMake 将 QtMultimedia 组件集成到项目中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52170097/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com