【问题标题】:Compiling with QT: libGL.so.1 not found使用 QT 编译:找不到 libGL.so.1
【发布时间】:2018-07-24 16:03:44
【问题描述】:

我在使用 CMake 后尝试使用 make 编译一个简单的 Qt 程序,但我不断收到此错误:

/usr/bin/ld: warning: libGL.so.1, needed by /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1, not found (try using -rpath or -rpath-link)
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glGetTexParameterfv'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glHint'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glClearColor'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glFlush'
...
collect2: error: ld returned 1 exit status

我已经通过sudo apt install --reinstall libgl1-mesa-dev 重新安装了libgl1-mesa-dev,确保在我的/usr/lib/x86_64-linux-gnu/mesa 目录中安装了libGL.so.1,并且我运行sudo ldconfig 无济于事。

我不确定是什么原因造成的,我还没有在其他任何地方看到过这个问题。这似乎是我忽略的一个依赖项,但是我使用 sudo apt install qt5-default 安装了 Qt,所以我认为这些依赖项会得到处理。

这是我的 CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

project(SimpleQt)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_AUTOMOC ON)

find_package(Qt5Widgets CONFIG REQUIRED)

include_directories(include)

add_executable(SimpleQt src/main.cpp)

target_link_libraries(growth Qt5::Widgets)

【问题讨论】:

  • 非常相似的问题,见this answer
  • 谢谢。我设法让它工作,但我仍然觉得我不应该自己与 OpenGL 链接。

标签: c++ qt opengl cmake


【解决方案1】:

感谢 cmets 中的 Ripi2,我找到了一种让它工作的方法。显然我必须将 OpenGL 与我的项目联系起来。这是我更新的 CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

project(SimpleQt)

set(CMAKE_CXX_STANDARD 11)

set(CMAKE_AUTOMOC ON)

find_package(OpenGL Required) # Added this line
find_package(Qt5Widgets CONFIG REQUIRED)

include_directories(include ${OPENGL_INCLUDE_DIRS}) # Updated this line

add_executable(SimpleQt src/main.cpp)

target_link_libraries(growth Qt5::Widgets ${OPENGL_LIBRARIES}) # Updated this line

我没有回答这个问题,因为这绝对不是应该的样子。 Qt 网站上的所有示例都没有显示 OpenGL 作为链接要求,所以我觉得必须有更好的方法。

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多