簡體   English   中英

CMake 聲稱找到 OpenGL 但找不到 EGL 和 OpenGL::GL

[英]CMake claims finding OpenGL but can't find EGL and OpenGL::GL

嘗試在 Ubuntu 上查找 OpenGL 時,CMake 給了我令人困惑的結果。

上下文是我需要在沒有 X 顯示的服務器/docker 上進行無頭渲染。 我已經通過apt-get install libgl1-mesa-devapt-get install libegl1-mesa-dev

這是我的 CMakeLists.txt 中的相關部分:

cmake_minimum_required (VERSION 3.5.1)
project (sandbox LANGUAGES CXX)

# add OpenGL

find_package(OpenGL REQUIRED COMPONENTS OpenGL EGL GLX)
include_directories(${OPENGL_INCLUDE_DIRS})
if(OPENGL_FOUND)
    message("Found OpenGL in the current environment!")
else()
    message("Error: No OpenGL found.")
endif()

message("OpenGL include dirs" )
message("${OPENGL_INCLUDE_DIR}")
message("EGL include dirs" )
message("${OPENGL_EGL_INCLUDE_DIRS}")

if (OpenGL_EGL_FOUND)
    message("EGL Found!")
else()
    message("EGL Not Found!")
endif()

add_executable (sandbox "hello_egl.cpp" "shader.cpp")

target_link_libraries(sandbox PRIVATE OpenGL::OpenGL OpenGL::EGL OpenGL::GLX)

#target_include_directories(sandbox PRIVATE "/usr/include/EGL")
#target_link_libraries(sandbox "/usr/local/lib/x86_64-linux-gnu/libEGL.so")
#target_link_libraries(sandbox "/usr/local/lib/libEGL.so")

set_target_properties(sandbox PROPERTIES CXX_STANDARD 11)

這是我從運行cmake..得到的錯誤:

Found OpenGL in the current environment!
OpenGL include dirs
/usr/local/include
EGL include dirs

EGL Not Found!

-- Configuring done
CMake Error at CMakeLists.txt:44 (add_executable):
  Target "sandbox" links to target "OpenGL::OpenGL" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?


CMake Error at CMakeLists.txt:44 (add_executable):
  Target "sandbox" links to target "OpenGL::EGL" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?


CMake Error at CMakeLists.txt:44 (add_executable):
  Target "sandbox" links to target "OpenGL::GLX" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

令人困惑的是CMakeOPENGL_FOUND設置為true ,但無法鏈接到目標OpenGL::OpenGL

另外,我在/usr/local/lib/x86_64-linux-gnu/中有EGL ,但為什么 CMake 找不到它?

root@6442439c7090:/app/sandbox/build# ls /usr/local/lib/x86_64-linux-gnu/
libEGL.so        libGL.so.1         libGLESv1_CM.so.1.2.0  libGLX.so         libGLdispatch.so.0      libOpenGL.so.0.0.0
libEGL.so.1      libGL.so.1.7.0     libGLESv2.so           libGLX.so.0       libGLdispatch.so.0.0.0  pkgconfig
libEGL.so.1.1.0  libGLESv1_CM.so    libGLESv2.so.2         libGLX.so.0.0.0   libOpenGL.so
libGL.so         libGLESv1_CM.so.1  libGLESv2.so.2.1.0     libGLdispatch.so  libOpenGL.so.0

我堅持使用find_package的原因是以前我手動鏈接到libEGL.so但應用程序在運行時無法顯示。 所以我懷疑我鏈接到了錯誤的庫。

terminate called after throwing an instance of 'std::runtime_error'
  what():  EGL error 0x300c at eglGetDisplay
Aborted (core dumped)

根據@Tsyvarev 的有用評論,這個 output 是由於 CMake 的錯誤版本造成的。

我忘了鏈接它,但我查看的FindOpenGL 文檔適用於 3.18.1 版本,而我要求最低 CMake 版本為 3.5.1。

在 3.5.1 中,沒有COMPONENTS部分。 OPENGL_FOUND也不檢查EGL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM