首页 > 解决方案 > android c++ 未定义对 eglGetCurrentContext 的引用

问题描述

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

但我得到一个编译时错误,我怎样才能得到当前的上下文?

错误:

undefined reference to eglGetCurrentContext()

编码:

#include <GLES2/gl2.h>
#include <EGL/egl.h>

void foo()
{
    EGLContext ctx = eglGetCurrentContext();
}

标签: androidc++opengl-esandroid-ndkopengl-es-2.0

解决方案


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

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

# Include libraries needed
target_link_libraries(
            GLESv2
            EGL)

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


推荐阅读