dev dev
dev dev

Reputation: 139

undefined reference to `glReadBuffer' in Android

I try to create a JNI GLES3 renderer. Here is my 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})

When I use so GLES function like glReadBuffer I get error:

  /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'

During the compilation the GLES library is well added to the compile command:

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" && :

I don't knwo if I had to add so #define things to the cpp program to be able to use these functions.

Can someone help me with that?

Upvotes: 0

Views: 1502

Answers (1)

Raki
Raki

Reputation: 329

I can clearly see in your code that you are linking openGL ES 2.0 libraries. As far as I knew glReadBuffer,glMapBufferRange and glUnmapBuffer are part of openGL ES 3 which obviously won't be there in in GLESv2 lib. So you need to change GLES lib to proper one.

Upvotes: 1

Related Questions