android c++ undefined reference to eglGetCurrentContext

android c++ undefined reference to eglGetCurrentContext

本文关键字:to eglGetCurrentContext reference undefined c++ android      更新时间:2023-10-16

我正在尝试在 c++ 中获取 android 上的当前 OpenGL 上下文。

但是我收到编译时错误,如何获取当前上下文?

错误:

undefined reference to eglGetCurrentContext()

代码:

#include <GLES2/gl2.h>
#include <EGL/egl.h>
void foo()
{
    EGLContext ctx = eglGetCurrentContext();
}

您的 make 文件库列表中缺少 libEGL。

假设您使用的是 CMake 文件,您的 make 文件中需要这样的东西:

# Include libraries needed
target_link_libraries(
            GLESv2
            EGL)

注意 此错误不需要GLESv2,但鉴于您包含 GLES2 标头,您可能在某些时候需要 GLESv2 库......