我的OpenGL学习进阶之旅解决NDK使用OpenGL ES 3.0 的api报错:error: undefined reference to ‘glUnmapBuffer‘

Posted 欧阳鹏

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我的OpenGL学习进阶之旅解决NDK使用OpenGL ES 3.0 的api报错:error: undefined reference to ‘glUnmapBuffer‘相关的知识,希望对你有一定的参考价值。

一、错误描述

今天在写一个OpenGL ES 3.0的demo的时候,编译报错,如下所示:

D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp
:162: error: undefined reference to 'glUnmapBuffer'

完整错误日志,如下所示:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process C:\\android\\sdk\\cmake\\3.10.2.4988404\\bin\\ninja.exe with arguments {-C D:\\GitLab Source\\OpenGLESDemo\\app\\.cxx\\cmake\\debug\\armeabi-v7a opengles-lesson-lib}
  ninja: Entering directory `D:\\GitLab Source\\OpenGLESDemo\\app\\.cxx\\cmake\\debug\\armeabi-v7a'
  [1/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/lesson1/Native1Lesson.cpp.o
  [2/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle.cpp.o
  [3/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle3.cpp.o
  [4/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/graphics/GLUtils.cpp.o
  [5/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle2.cpp.o
  [6/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o
  [7/8] Building CXX object CMakeFiles/opengles-lesson-lib.dir/graphics/Matrix.cpp.o
  [8/8] Linking CXX shared library "D:\\GitLab Source\\OpenGLESDemo\\app\\build\\intermediates\\cmake\\debug\\obj\\armeabi-v7a\\libopengles-lesson-lib.so"
  FAILED: D:/GitLab Source/OpenGLESDemo/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libopengles-lesson-lib.so 
  cmd.exe /C "cd . && C:\\Android\\SDK\\ndk-bundle\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -std=c++11 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libopengles-lesson-lib.so -o "D:\\GitLab Source\\OpenGLESDemo\\app\\build\\intermediates\\cmake\\debug\\obj\\armeabi-v7a\\libopengles-lesson-lib.so" CMakeFiles/opengles-lesson-lib.dir/graphics/GLUtils.cpp.o CMakeFiles/opengles-lesson-lib.dir/graphics/Matrix.cpp.o CMakeFiles/opengles-lesson-lib.dir/lesson1/Native1Lesson.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle2.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle3.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o  -lEGL -lGLESv2 -landroid -llog -latomic -lm && cd ."
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:125: error: undefined reference to 'glMapBufferRange'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:138: error: undefined reference to 'glUnmapBuffer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:150: error: undefined reference to 'glMapBufferRange'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp:162: error: undefined reference to 'glUnmapBuffer'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.
  


* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 11s
12 actionable tasks: 7 executed, 5 up-to-date

二、排查问题

我们排查上面的错误日志,发现有一条命令是

CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o 
        -lEGL -lGLESv2 -landroid -llog -latomic -lm

咋回事,怎么是-lGLESv2

查看下CMakeList.txt代码,原来配置GLES版本配置成了GLESv2

target_link_libraries( # Specifies the target library.
        opengles-lesson-lib

        EGL
        GLESv2
        android

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

我们将GLESv2改成GLESv3 即可。

target_link_libraries( # Specifies the target library.
        opengles-lesson-lib

        EGL
        GLESv3  # OpenGL ES 3.0版本
        android

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

然后重新编译一下。

三、新问题

上面将CMakeList.txt代码,原来配置的GLESv2改成GLESv3,那么error: undefined reference to 'glUnmapBuffer'的问题不存在了。

但是产生了新的问题,如下所示:

D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangleMapBuffers.cpp
:188: error: undefined reference to 'glDisableVertexAttribArray'


但是我们点开代码,进入gl3.h 可以看到有这个API的。

完整错误日志如下所示:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
  Error while executing process C:\\Android\\sdk\\cmake\\3.10.2.4988404\\bin\\ninja.exe with arguments {-C D:\\GitLab Source\\OpenGLESDemo\\app\\.cxx\\cmake\\debug\\armeabi-v7a opengles-lesson-lib}
  ninja: Entering directory `D:\\GitLab Source\\OpenGLESDemo\\app\\.cxx\\cmake\\debug\\armeabi-v7a'
  [1/1] Linking CXX shared library "D:\\GitLab Source\\OpenGLESDemo\\app\\build\\intermediates\\cmake\\debug\\obj\\armeabi-v7a\\libopengles-lesson-lib.so"
  FAILED: D:/GitLab Source/OpenGLESDemo/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libopengles-lesson-lib.so 
  cmd.exe /C "cd . && C:\\Android\\SDK\\ndk-bundle\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -std=c++11 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libopengles-lesson-lib.so -o "D:\\GitLab Source\\OpenGLESDemo\\app\\build\\intermediates\\cmake\\debug\\obj\\armeabi-v7a\\libopengles-lesson-lib.so" CMakeFiles/opengles-lesson-lib.dir/graphics/GLUtils.cpp.o CMakeFiles/opengles-lesson-lib.dir/graphics/Matrix.cpp.o CMakeFiles/opengles-lesson-lib.dir/lesson1/Native1Lesson.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle2.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangle3.cpp.o CMakeFiles/opengles-lesson-lib.dir/triangle/NativeTriangleMapBuffers.cpp.o  -lEGL -lGLESv3 -landroid -llog -latomic -lm && cd ."
  C:/Android/SDK/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\\ld: error: cannot find -lGLESv3
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:78: error: undefined reference to 'glCreateProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:84: error: undefined reference to 'glAttachShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:87: error: undefined reference to 'glAttachShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:90: error: undefined reference to 'glLinkProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:94: error: undefined reference to 'glGetProgramiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:99: error: undefined reference to 'glGetProgramiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:103: error: undefined reference to 'glGetProgramInfoLog'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:109: error: undefined reference to 'glDeleteProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:113: error: undefined reference to 'glDeleteShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:114: error: undefined reference to 'glDeleteShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:31: error: undefined reference to 'glCreateShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:37: error: undefined reference to 'glShaderSource'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:40: error: undefined reference to 'glCompileShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:43: error: undefined reference to 'glGetShaderiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:48: error: undefined reference to 'glGetShaderiv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:53: error: undefined reference to 'glGetShaderInfoLog'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/graphics/GLUtils.cpp:59: error: undefined reference to 'glDeleteShader'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:5: error: undefined reference to 'glGetString'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:131: error: undefined reference to 'glViewport'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:147: error: undefined reference to 'glClearColor'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:148: error: undefined reference to 'glClear'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:151: error: undefined reference to 'glUseProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:154: error: undefined reference to 'glGetUniformLocation'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:155: error: undefined reference to 'glGetAttribLocation'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:156: error: undefined reference to 'glGetAttribLocation'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:10: error: undefined reference to 'glGetError'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:10: error: undefined reference to 'glGetError'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:183: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:191: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:193: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:201: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:209: error: undefined reference to 'glUniformMatrix4fv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/lesson1/Native1Lesson.cpp:211: error: undefined reference to 'glDrawArrays'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:76: error: undefined reference to 'glClearColor'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:8: error: undefined reference to 'glGetString'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:84: error: undefined reference to 'glViewport'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:93: error: undefined reference to 'glClear'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:98: error: undefined reference to 'glUseProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:122: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:126: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle.cpp:138: error: undefined reference to 'glDrawArrays'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:8: error: undefined reference to 'glGetString'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:86: error: undefined reference to 'glClearColor'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:94: error: undefined reference to 'glViewport'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:103: error: undefined reference to 'glClear'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:108: error: undefined reference to 'glUseProgram'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:133: error: undefined reference to 'glVertexAttribPointer'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:137: error: undefined reference to 'glEnableVertexAttribArray'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp:146: error: undefined reference to 'glVertexAttrib4fv'
  D:/GitLab Source/OpenGLESDemo/app/src/main/cpp/triangle/NativeTriangle2.cpp我的OpenGL学习进阶之旅NDK开发中find_library查找的系统动态库在哪里?

我的OpenGL学习进阶之旅NDK开发中find_library查找的系统动态库在哪里?

我的OpenGL学习进阶之旅解决使用VAO的时候误用glDisableVertexAttribArray导致无法渲染出现白屏或者黑屏的问题

我的OpenGL学习进阶之旅解决使用VAO的时候误用glDisableVertexAttribArray导致无法渲染出现白屏或者黑屏的问题

我的Android进阶之旅解决NDK开发,编译的时候报错:open: Invalid argument File xxx.so is not writable.

我的OpenGL学习进阶之旅解决着色器语法错误:ERROR: 0:36: ‘*‘ : wrong operand types no operation ‘*‘ exists