Issue
I am trying to update a GitHub repo, which is a basic OpenGL rendered cube, to a current Android version and project structure. The CMake script seems to be missing something, which I can't figure out. Is it a simple issue of lines in the wrong order?
System: Arch Linux - Kernel 5.0.9, Android Studio 3.5 Canary 13, CMake 3.14.3, Ninja 1.9.0
I created a new Native project in Android Studio and filled in the configurations with the old data. You can see the progress here. I am stuck at trying to link the GL function libraries to the .cpp files, as the terminal output tells me there are undefined references to certain gl... functions.
Terminal output:
Build command failed.
Error while executing process /usr/bin/ninja with arguments {-C /home/snobo/projects/AndroidNativeExample/app/.cxx/cmake/debug/armeabi-v7a nativeegl}
ninja: Entering directory `/home/snobo/projects/AndroidNativeExample/app/.cxx/cmake/debug/armeabi-v7a'
[1/2] Building CXX object CMakeFiles/nativeegl.dir/renderer.cpp.o
[2/2] Linking CXX shared library /home/snobo/projects/AndroidNativeExample/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnativeegl.so
FAILED: /home/snobo/projects/AndroidNativeExample/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnativeegl.so
: && /home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi28 --gcc-toolchain=/home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mfpu=vfpv3-d16 -fno-addrsig -march=armv7-a -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++14 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnativeegl.so -o /home/snobo/projects/AndroidNativeExample/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnativeegl.so CMakeFiles/nativeegl.dir/jniapi.cpp.o CMakeFiles/nativeegl.dir/renderer.cpp.o /home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/28/liblog.so -landroid -lGLESv3 -lEGL -latomic -lm && :
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:230: error: undefined reference to 'glShadeModel'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:236: error: undefined reference to 'glMatrixMode'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:237: error: undefined reference to 'glLoadIdentity'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:238: error: undefined reference to 'glFrustumf'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:262: error: undefined reference to 'glMatrixMode'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:263: error: undefined reference to 'glLoadIdentity'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:264: error: undefined reference to 'glTranslatef'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:265: error: undefined reference to 'glRotatef'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:266: error: undefined reference to 'glRotatef'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:268: error: undefined reference to 'glEnableClientState'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:269: error: undefined reference to 'glEnableClientState'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:272: error: undefined reference to 'glVertexPointer'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:273: error: undefined reference to 'glColorPointer'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Here is one of the methods that includes the errors from above:
void Renderer::drawFrame()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -3.0f);
glRotatef(_angle, 0, 1, 0);
glRotatef(_angle*0.25f, 1, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glFrontFace(GL_CW);
glVertexPointer(3, GL_FIXED, 0, vertices);
glColorPointer(4, GL_FIXED, 0, colors);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
_angle += 1.2f;
}
CMakeLists.txt:
project(AndroidNativeExample C CXX)
cmake_minimum_required(VERSION 3.4.1)
add_library(
nativeegl
SHARED
jniapi.cpp renderer.cpp)
include_directories(src/main/cpp/include/)
find_library( # Sets the name of the path variable.
log-lib
log)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(nativeegl Threads::Threads)
add_library(app-glue
STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
target_link_libraries(nativeegl ${app-glue})
target_link_libraries(nativeegl ${log-lib})
target_link_libraries(nativeegl android)
target_link_libraries(nativeegl GLESv3)
target_link_libraries(nativeegl EGL)
To my knowledge (which indeed is quite limited) this should link all necessary libraries and not result in an error. But somehow a few function references are undefined.
Please let me know if you have any ideas, I will try each and give feedback.
Solution
The missing functions glShadeModel
etc are OpenGL functions and are not available in OpenGL ES.
As your project managed to compile (and failed when linking) you must be including OpenGL headers from another source instead of the OpenGL ES header from the Android NDK.
Answered By - Richard Critten
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.