当我尝试通过 CMake 编译我的 OpenGL 程序时出现“对 `gladLoadGLES2Loader' 的未定义引用”

问题描述 投票:0回答:0

这是我的 CMakeLists.txt:

cmake_minimum_required(VERSION 3.26.3)
project(opengl VERSION 1.0.0)

find_library(LIBS NAMES glfw3 glad ${CMAKE_SOURCE_DIR}/lib)

add_executable(opengl src/main.cpp)
target_include_directories(opengl PRIVATE ${CMAKE_SOURCE_DIR}/lib/include)

target_link_libraries(opengl ${LIBS} dl X11 pthread)

这是输出:

/usr/bin/ld: CMakeFiles/opengl.dir/src/main.cpp.o: in function `main':
main.cpp:(.text+0xf8): undefined reference to `gladLoadGLES2Loader'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/opengl.dir/build.make:98: opengl] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/opengl.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

我正在按照教程 (learnopengl.com) 了解我目前编写的代码,唯一的区别是将代码从 OpenGL 3.3 反向移植到 OpenGL-ES 2.0。 变化来自

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
if (!gladLoadGLES2Loader((GLADloadproc)glfwGetProcAddress))
是除了 GLFW 窗口提示之外我必须做的唯一改变。

我不确定为什么当我在 CMakeLists 中包含 GLAD 并在 main.cpp 中包含 GLAD 并且 GLFW 似乎没有任何问题时,为什么这个特定函数未定义。

    

c++ opengl cmake graphics opengl-es-2.0
© www.soinside.com 2019 - 2024. All rights reserved.