在Android中未定义对`glReadBuffer'的引用

时间:2018-08-28 08:44:15

标签: opengl-es opengl-es-2.0

我尝试创建JNI GLES3渲染器。这是我的CmakeLists.txt:

set(CMAKE_VERBOSE_MAKEFILE on)
project("librenderer")

add_definitions("-std=c++11")

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             librenderer

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/jni/renderer/gl_utils.cpp
             src/main/jni/renderer/gpu_renderer.cpp
             src/main/jni/renderer/rendererjni_wrapper.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

find_library( # Sets the name of the path variable.
            GLESv2-lib

            # Specifies the name of the NDK library that
            # you want CMake to locate.
            GLESv2 )


find_library( # Sets the name of the path variable.
            EGL-lib

            # Specifies the name of the NDK library that
            # you want CMake to locate.
            EGL )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       librenderer

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib}
                       ${GLESv2-lib}
                       ${EGL-lib})

当我使用像glReadBuffer这样的GLES函数时,出现错误:

  /home/xavier/dev/myapp/src/main/jni/renderer/gl_utils.cpp:171: undefined reference to `glReadBuffer'
  /home/xavier/dev/myapp/src/main/jni/renderer/gl_utils.cpp:174: undefined reference to `glMapBufferRange'
  /home/xavier/dev/myapp/src/main/jni/renderer/gl_utils.cpp:180: undefined reference to `glUnmapBuffer'

在编译过程中,将GLES库很好地添加到了compile命令中:

AILED: : && /home/xavier/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=aarch64-none-linux-android --gcc-toolchain=/home/xavier/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 --sysroot=/home/xavier/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /home/xavier/Android/Sdk/ndk-bundle/sysroot/usr/include/aarch64-linux-android -D__ANDROID_API__=24 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security   -O2 -DNDEBUG  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot /home/xavier/Android/Sdk/ndk-bundle/platforms/android-24/arch-arm64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,liblibrenderer.so -o ../../../../build/intermediates/cmake/release/obj/arm64-v8a/liblibrenderer.so CMakeFiles/librenderer.dir/src/main/jni/renderer/gl_utils.cpp.o CMakeFiles/librenderer.dir/src/main/jni/renderer/gpu_renderer.cpp.o CMakeFiles/librenderer.dir/src/main/jni/renderer/rendererjni_wrapper.cpp.o  /home/xavier/Android/Sdk/ndk-bundle/platforms/android-24/arch-arm64/usr/lib/liblog.so /home/xavier/Android/Sdk/ndk-bundle/platforms/android-24/arch-arm64/usr/lib/libGLESv2.so /home/xavier/Android/Sdk/ndk-bundle/platforms/android-24/arch-arm64/usr/lib/libEGL.so -latomic -lm "/home/xavier/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a" && :

如果要在cpp程序中添加#define内容以便能够使用这些功能,我不知道。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

在您的代码中我可以清楚地看到您正在链接openGL ES 2.0库。据我所知glReadBuffer,glMapBufferRange and glUnmapBuffer是openGL ES 3的一部分,显然它不在GLESv2库中。因此,您需要将GLES lib更改为正确的lib。