我正在尝试将GitHub repo(这是一个基本的OpenGL呈现的多维数据集)更新为当前的Android版本和项目结构。 CMake脚本似乎丢失了一些内容,我无法弄清楚。这是一个简单的按错误顺序排列的线吗?
系统:Arch Linux-内核5.0.9,Android Studio 3.5 Canary 13,CMake 3.14.3,Ninja 1.9.0
我在Android Studio中创建了一个新的Native项目,并在配置中填充了旧数据。您可以看到进度here。我一直试图将GL函数库链接到.cpp文件,因为终端输出告诉我某些gl ...函数存在未定义的引用。
端子输出:
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.
这是包含上述错误的方法之一:
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)
据我所知(确实非常有限),这应该链接所有必需的库,并且不会导致错误。但是某种程度上,一些函数引用是不确定的。
如果您有任何想法,请告诉我,我会尽力提供反馈。
答案 0 :(得分:0)
缺少的功能glShadeModel
等是OpenGL函数,在OpenGL ES中不可用。
由于您的项目设法进行了编译(并且在链接时失败),因此您必须包括其他来源的OpenGL标头,而不是Android NDK的OpenGL ES标头。